Skip to content

Commit 42c3226

Browse files
ShahzaibIbrahimakoch-yatta
authored andcommitted
Deprecating Display#getDPI
Having the scale factor being based on the screen DPI leads to unexpected result e.g. Image too big/small. Having a screen dpi independent factor leads to consistent results.
1 parent 383ed2a commit 42c3226

File tree

7 files changed

+40
-1
lines changed

7 files changed

+40
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT Printing/cocoa/org/eclipse/swt/printing/Printer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ public Point getDPI() {
623623
}
624624
}
625625

626+
@SuppressWarnings("deprecation")
626627
Point getIndependentDPI() {
627628
return super.getDPI();
628629
}

bundles/org.eclipse.swt/Eclipse SWT Printing/win32/org/eclipse/swt/printing/PDFDocument.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public PDFDocument(Device device, String filename, double width, double height)
215215
int screenDpiX = 96;
216216
int screenDpiY = 96;
217217
if (this.device != null) {
218+
@SuppressWarnings("deprecation")
218219
Point dpi = this.device.getDPI();
219220
screenDpiX = dpi.x;
220221
screenDpiY = dpi.y;
@@ -427,6 +428,7 @@ public long internal_new_GC(GCData data) {
427428
int screenDpiX = 96;
428429
int screenDpiY = 96;
429430
if (device != null) {
431+
@SuppressWarnings("deprecation")
430432
Point dpi = device.getDPI();
431433
screenDpiX = dpi.x;
432434
screenDpiY = dpi.y;

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,18 @@ public int getDepth () {
391391
* @exception SWTException <ul>
392392
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
393393
* </ul>
394+
*
395+
* @deprecated <p>This method returns a single global DPI value
396+
* that does not reflect per-monitor DPI settings on modern operating systems.
397+
* In environments with different scaling factors across monitors, it may provide
398+
* a misleading or meaningless result, as it does not correspond to the actual DPI
399+
* of any specific monitor.</p>
400+
*
401+
* <p>Note: While deprecated for general {@code Device} instances like {@code Display},
402+
* this method may still be validly used when called on a {@code Printer} instance,
403+
* where a single global DPI value is meaningful and expected.</p>
394404
*/
405+
@Deprecated
395406
public Point getDPI () {
396407
checkDevice ();
397408
return getScreenDPI();

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,18 @@ public int getDepth () {
455455
* @exception SWTException <ul>
456456
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
457457
* </ul>
458+
*
459+
* @deprecated <p>This method returns a single global DPI value
460+
* that does not reflect per-monitor DPI settings on modern operating systems.
461+
* In environments with different scaling factors across monitors, it may provide
462+
* a misleading or meaningless result, as it does not correspond to the actual DPI
463+
* of any specific monitor.</p>
464+
*
465+
* <p>Note: While deprecated for general {@code Device} instances like {@code Display},
466+
* this method may still be validly used when called on a {@code Printer} instance,
467+
* where a single global DPI value is meaningful and expected.</p>
458468
*/
469+
@Deprecated
459470
public Point getDPI () {
460471
checkDevice ();
461472
return getScreenDPI();

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5052,7 +5052,9 @@ String debugInfoForIndex(long index) {
50525052
}
50535053

50545054
void dpiChanged(int newScaleFactor) {
5055-
DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(getDPI().x * newScaleFactor));
5055+
@SuppressWarnings("deprecation")
5056+
int dpiX = getDPI().x;
5057+
DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(dpiX * newScaleFactor));
50565058
Shell[] shells = getShells();
50575059
for (int i = 0; i < shells.length; i++) {
50585060
shells[i].layout(true, true);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,18 @@ public int getDepth () {
519519
* @exception SWTException <ul>
520520
* <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
521521
* </ul>
522+
*
523+
* @deprecated <p>This method returns a single global DPI value
524+
* that does not reflect per-monitor DPI settings on modern operating systems.
525+
* In environments with different scaling factors across monitors, it may provide
526+
* a misleading or meaningless result, as it does not correspond to the actual DPI
527+
* of any specific monitor.</p>
528+
*
529+
* <p>Note: While deprecated for general {@code Device} instances like {@code Display},
530+
* this method may still be validly used when called on a {@code Printer} instance,
531+
* where a single global DPI value is meaningful and expected.</p>
522532
*/
533+
@Deprecated
523534
public Point getDPI () {
524535
checkDevice ();
525536
long hDC = internal_new_GC (null);

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,7 @@ public void test_wake() {
15531553
/* custom */
15541554
boolean disposeExecRan;
15551555

1556+
@SuppressWarnings("deprecation")
15561557
@Test
15571558
public void test_getDPI() {
15581559
Display display = new Display();

0 commit comments

Comments
 (0)