Skip to content

Commit 37b8bb4

Browse files
committed
DisplayServer: reports DPI instead of scaled resolution
Fixes #2224
1 parent 66edea7 commit 37b8bb4

15 files changed

Lines changed: 76 additions & 89 deletions

src/detection/displayserver/displayserver.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ FFDisplayResult* ffdsAppendDisplay(
55
uint32_t width,
66
uint32_t height,
77
double refreshRate,
8-
uint32_t scaledWidth,
9-
uint32_t scaledHeight,
8+
uint32_t dpi,
109
uint32_t preferredWidth,
1110
uint32_t preferredHeight,
1211
double preferredRefreshRate,
@@ -26,8 +25,7 @@ FFDisplayResult* ffdsAppendDisplay(
2625
display->width = width;
2726
display->height = height;
2827
display->refreshRate = refreshRate;
29-
display->scaledWidth = scaledWidth;
30-
display->scaledHeight = scaledHeight;
28+
display->dpi = dpi ?: 96; // 0 means unknown
3129
display->preferredWidth = preferredWidth;
3230
display->preferredHeight = preferredHeight;
3331
display->preferredRefreshRate = preferredRefreshRate;

src/detection/displayserver/displayserver.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ typedef struct FFDisplayResult
7272
uint32_t width; // in px
7373
uint32_t height; // in px
7474
double refreshRate; // in Hz
75-
uint32_t scaledWidth; // in px
76-
uint32_t scaledHeight; // in px
75+
uint32_t dpi; // Base 96
7776
uint32_t preferredWidth; // in px
7877
uint32_t preferredHeight; // in px
7978
double preferredRefreshRate; // in Hz
@@ -110,8 +109,7 @@ FFDisplayResult* ffdsAppendDisplay(
110109
uint32_t width,
111110
uint32_t height,
112111
double refreshRate,
113-
uint32_t scaledWidth,
114-
uint32_t scaledHeight,
112+
uint32_t dpi,
115113
uint32_t preferredWidth,
116114
uint32_t preferredHeight,
117115
double preferredRefreshRate,

src/detection/displayserver/displayserver_android.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void detectWithDumpsys(FFDisplayServerResult* ds)
8585
FFDisplayResult* display = ffdsAppendDisplay(ds,
8686
(uint32_t)width, (uint32_t)height,
8787
refreshRate,
88-
0, 0,
88+
0,
8989
0, 0,
9090
0,
9191
0,
@@ -117,11 +117,11 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
117117
ffStrbufSubstrAfterFirstC(&buffer, ',');
118118
uint32_t height = (uint32_t) ffStrbufToUInt(&buffer, 0);
119119
ffStrbufSubstrAfterFirstC(&buffer, ',');
120-
double scaleFactor = (double) ffStrbufToUInt(&buffer, 0) / 160.;
120+
uint32_t dpi = (uint32_t) ffStrbufToUInt(&buffer, 0) * 96 / 160;
121121
FFDisplayResult* display = ffdsAppendDisplay(ds,
122122
width, height,
123123
0,
124-
(uint32_t) (width / scaleFactor + .5), (uint32_t) (height / scaleFactor + .5),
124+
dpi,
125125
0, 0,
126126
0,
127127
0,

src/detection/displayserver/displayserver_apple.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ static void detectDisplays(FFDisplayServerResult* ds)
116116
physicalHeight = (uint32_t) (size.height + 0.5);
117117
}
118118

119+
uint32_t pixelWidth = (uint32_t) CGDisplayModeGetPixelWidth(mode);
120+
uint32_t pixelHeight = (uint32_t) CGDisplayModeGetPixelHeight(mode);
121+
119122
FFDisplayResult* display = ffdsAppendDisplay(ds,
120-
(uint32_t)CGDisplayModeGetPixelWidth(mode),
121-
(uint32_t)CGDisplayModeGetPixelHeight(mode),
123+
pixelWidth,
124+
pixelHeight,
122125
refreshRate,
123-
(uint32_t)CGDisplayModeGetWidth(mode),
124-
(uint32_t)CGDisplayModeGetHeight(mode),
126+
pixelHeight * 96 / (uint32_t)CGDisplayModeGetHeight(mode),
125127
preferredWidth,
126128
preferredHeight,
127129
preferredRefreshRate,

src/detection/displayserver/displayserver_haiku.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ static void detectDisplays(FFDisplayServerResult* ds)
3737

3838
uint32_t width = (uint32_t) s.Frame().Width() + 1;
3939
uint32_t height = (uint32_t) (uint32_t)s.Frame().Height() + 1;
40-
double scaleFactor = (double) 1.0;
4140
FFDisplayResult* res = ffdsAppendDisplay(ds,
4241
width,
4342
height,
4443
(double)mode.timing.pixel_clock * 1000 / (mode.timing.v_total * mode.timing.h_total),
45-
(uint32_t) (width / scaleFactor + .5),
46-
(uint32_t) (height / scaleFactor + .5),
44+
0,
4745
0,
4846
0,
4947
0,

src/detection/displayserver/displayserver_windows.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,6 @@ static void detectDisplays(FFDisplayServerResult* ds)
9393

9494
uint32_t width = sourceMode->width;
9595
uint32_t height = sourceMode->height;
96-
if (path->targetInfo.rotation == DISPLAYCONFIG_ROTATION_ROTATE90 ||
97-
path->targetInfo.rotation == DISPLAYCONFIG_ROTATION_ROTATE270)
98-
{
99-
uint32_t temp = width;
100-
width = height;
101-
height = temp;
102-
temp = physicalWidth;
103-
physicalWidth = physicalHeight;
104-
physicalHeight = temp;
105-
}
106-
10796
uint32_t rotation;
10897
switch (path->targetInfo.rotation)
10998
{
@@ -144,12 +133,19 @@ static void detectDisplays(FFDisplayServerResult* ds)
144133
ReleaseDC(NULL, hdc);
145134
}
146135

136+
if (path->targetInfo.rotation == DISPLAYCONFIG_ROTATION_ROTATE90 ||
137+
path->targetInfo.rotation == DISPLAYCONFIG_ROTATION_ROTATE270)
138+
{
139+
uint32_t temp = width;
140+
width = height;
141+
height = temp;
142+
}
143+
147144
FFDisplayResult* display = ffdsAppendDisplay(ds,
148145
width,
149146
height,
150147
path->targetInfo.refreshRate.Numerator / (double) path->targetInfo.refreshRate.Denominator,
151-
width * 96 / systemDpi,
152-
height * 96 / systemDpi,
148+
systemDpi,
153149
preferredMode.width,
154150
preferredMode.height,
155151
preferredRefreshRate,

src/detection/displayserver/linux/displayserver_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
7979
if (ffSettingsGetFreeBSDKenv("screen.height", &buf))
8080
{
8181
uint32_t height = (uint32_t) ffStrbufToUInt(&buf, 0);
82-
ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0, 0, 0, "kenv");
82+
ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0, 0, 0, "kenv");
8383
}
8484
}
8585
}

src/detection/displayserver/linux/drm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static const char* drmParseSysfs(FFDisplayServerResult* result)
8383
result,
8484
width, height,
8585
refreshRate,
86-
0, 0,
86+
0,
8787
0, 0,
8888
0,
8989
0,
@@ -398,7 +398,7 @@ static const char* drmConnectLibdrm(FFDisplayServerResult* result)
398398
FFDisplayResult* item = ffdsAppendDisplay(result,
399399
width, height,
400400
refreshRate,
401-
0, 0,
401+
0,
402402
preferredWidth, preferredHeight,
403403
preferredRefreshRate,
404404
0,

src/detection/displayserver/linux/wayland/global-output.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void waylandOutputModeListener(void* data, FF_MAYBE_UNUSED struct wl_outp
2525
static void waylandOutputScaleListener(void* data, FF_MAYBE_UNUSED struct wl_output* output, int32_t scale)
2626
{
2727
WaylandDisplay* display = data;
28-
display->scale = scale;
28+
display->dpi = 96 * (uint32_t) scale;
2929
}
3030

3131
static void waylandOutputGeometryListener(void *data,
@@ -51,7 +51,7 @@ static void handleXdgLogicalSize(void *data, FF_MAYBE_UNUSED struct zxdg_output_
5151
// Seems the values are only useful when ractional scale is enabled
5252
if (width < display->width)
5353
{
54-
display->scale = (double) display->width / width;
54+
display->dpi = (uint32_t) (display->width * 96 / width);
5555
}
5656
}
5757

@@ -86,7 +86,6 @@ const char* ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry*
8686

8787
WaylandDisplay display = {
8888
.parent = wldata,
89-
.scale = 1,
9089
.transform = WL_OUTPUT_TRANSFORM_NORMAL,
9190
.type = FF_DISPLAY_TYPE_UNKNOWN,
9291
.name = ffStrbufCreate(),
@@ -128,8 +127,7 @@ const char* ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry*
128127
(uint32_t) display.width,
129128
(uint32_t) display.height,
130129
display.refreshRate / 1000.0,
131-
(uint32_t) (display.width / display.scale + .5),
132-
(uint32_t) (display.height / display.scale + .5),
130+
display.dpi,
133131
(uint32_t) display.preferredWidth,
134132
(uint32_t) display.preferredHeight,
135133
display.preferredRefreshRate / 1000.0,

src/detection/displayserver/linux/wayland/kde-output.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void waylandKdeCurrentModeListener(void* data, FF_MAYBE_UNUSED struct kde
8383
static void waylandKdeScaleListener(void* data, FF_MAYBE_UNUSED struct kde_output_device_v2* _, wl_fixed_t scale)
8484
{
8585
WaylandDisplay* wldata = (WaylandDisplay*) data;
86-
wldata->scale = wl_fixed_to_double(scale);
86+
wldata->dpi = (uint32_t) scale * 3 / 8; // wl_fixed_to_double(scale) * 96;
8787
}
8888

8989
static void waylandKdeEdidListener(void* data, FF_MAYBE_UNUSED struct kde_output_device_v2* _, const char* raw)
@@ -193,7 +193,6 @@ const char* ffWaylandHandleKdeOutput(WaylandData* wldata, struct wl_registry* re
193193
FF_LIST_AUTO_DESTROY modes = ffListCreate(sizeof(WaylandKdeMode));
194194
WaylandDisplay display = {
195195
.parent = wldata,
196-
.scale = 1,
197196
.transform = WL_OUTPUT_TRANSFORM_NORMAL,
198197
.type = FF_DISPLAY_TYPE_UNKNOWN,
199198
.name = ffStrbufCreate(),
@@ -224,8 +223,7 @@ const char* ffWaylandHandleKdeOutput(WaylandData* wldata, struct wl_registry* re
224223
(uint32_t) display.width,
225224
(uint32_t) display.height,
226225
display.refreshRate / 1000.0,
227-
(uint32_t) (display.width / display.scale + .5),
228-
(uint32_t) (display.height / display.scale + .5),
226+
display.dpi,
229227
(uint32_t) display.preferredWidth,
230228
(uint32_t) display.preferredHeight,
231229
display.preferredRefreshRate / 1000.0,

0 commit comments

Comments
 (0)