@@ -46,6 +46,7 @@ void ScreenGrabber::generalGrimScreenshot(bool& ok, QPixmap& res)
4646 res.load (imgPath, " ppm" );
4747 QFile imgFile (imgPath);
4848 imgFile.remove ();
49+ adjustDevicePixelRatio (res);
4950 ok = true ;
5051 } else {
5152 ok = false ;
@@ -98,29 +99,7 @@ void ScreenGrabber::freeDesktopPortal(bool& ok, QPixmap& res)
9899 QUrl uri = map.value (" uri" ).toString ();
99100 QString uriString = uri.toLocalFile ();
100101 res = QPixmap (uriString);
101-
102- // we calculate an approximated physical desktop geometry based on
103- // dpr(provided by qt), we calculate the logical desktop geometry
104- // later, this is the accurate size, more info:
105- // https://bugreports.qt.io/browse/QTBUG-135612
106- QRect approxPhysGeo = desktopGeometry ();
107- QRect logicalGeo = logicalDesktopGeometry ();
108- if (res.size () ==
109- approxPhysGeo.size ()) // which means the res is physical size
110- // and the dpr is correct.
111- {
112- res.setDevicePixelRatio (qApp->devicePixelRatio ());
113- } else if (res.size () ==
114- logicalGeo.size ()) // which means the res is logical size
115- // and we need to do nothing.
116- {
117- // No action needed
118- } else // which means the res is physical size and the dpr is not
119- // correct.
120- {
121- res.setDevicePixelRatio (res.height () * 1 .0f /
122- logicalGeo.height ());
123- }
102+ adjustDevicePixelRatio (res);
124103 QFile imgFile (uriString);
125104 imgFile.remove ();
126105 }
@@ -303,3 +282,17 @@ QRect ScreenGrabber::logicalDesktopGeometry()
303282 }
304283 return geometry;
305284}
285+
286+ void ScreenGrabber::adjustDevicePixelRatio (QPixmap& pixmap)
287+ {
288+ QRect physicalGeo = desktopGeometry ();
289+ QRect logicalGeo = logicalDesktopGeometry ();
290+ if (pixmap.size () == physicalGeo.size ()) {
291+ // Pixmap is physical size and Qt's DPR is correct
292+ pixmap.setDevicePixelRatio (qApp->devicePixelRatio ());
293+ } else if (pixmap.size () != logicalGeo.size ()) {
294+ // Pixmap is physical size but Qt's DPR is incorrect, calculate actual
295+ pixmap.setDevicePixelRatio (pixmap.height () * 1 .0f /
296+ logicalGeo.height ());
297+ }
298+ }
0 commit comments