Title: [260127] trunk/Source/WebCore
Revision
260127
Author
[email protected]
Date
2020-04-15 07:54:52 -0700 (Wed, 15 Apr 2020)

Log Message

[GTK] Make PlatformScreen::screenDPI() GTK4-ready
https://bugs.webkit.org/show_bug.cgi?id=210543

Reviewed by Adrian Perez de Castro.

No new tests needed.

This method is using deprecated and removed APIs
from GDK. Guard the removed API usage so that it's only
used in GTK3 and update to use the replacement APIs otherwise.

Also, make it to also use the gtk-xft-dpi GtkSettings property.
This method is mostly used in response to a change in this
property, so ignoring its value doesn't seem a good idea.

The following priority is used:

1. (GTK3 only) query gdk_screen_get_resolution().
2. Use the GtkSettings::gtk-xft-dpi property.
3. Calculate the actual DPI from the monitor 0's properties.
4. If none of these succeed, use the default DPI, 96.

* platform/gtk/PlatformScreenGtk.cpp:
(WebCore::screenDPI):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260126 => 260127)


--- trunk/Source/WebCore/ChangeLog	2020-04-15 14:33:32 UTC (rev 260126)
+++ trunk/Source/WebCore/ChangeLog	2020-04-15 14:54:52 UTC (rev 260127)
@@ -1,3 +1,30 @@
+2020-04-15  Claudio Saavedra  <[email protected]>
+
+        [GTK] Make PlatformScreen::screenDPI() GTK4-ready
+        https://bugs.webkit.org/show_bug.cgi?id=210543
+
+        Reviewed by Adrian Perez de Castro.
+
+        No new tests needed.
+
+        This method is using deprecated and removed APIs
+        from GDK. Guard the removed API usage so that it's only
+        used in GTK3 and update to use the replacement APIs otherwise.
+
+        Also, make it to also use the gtk-xft-dpi GtkSettings property.
+        This method is mostly used in response to a change in this
+        property, so ignoring its value doesn't seem a good idea.
+
+        The following priority is used:
+
+        1. (GTK3 only) query gdk_screen_get_resolution().
+        2. Use the GtkSettings::gtk-xft-dpi property.
+        3. Calculate the actual DPI from the monitor 0's properties.
+        4. If none of these succeed, use the default DPI, 96.
+
+        * platform/gtk/PlatformScreenGtk.cpp:
+        (WebCore::screenDPI):
+
 2020-04-15  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Remove IconGtk

Modified: trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp (260126 => 260127)


--- trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp	2020-04-15 14:33:32 UTC (rev 260126)
+++ trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp	2020-04-15 14:54:52 UTC (rev 260127)
@@ -92,13 +92,21 @@
 double screenDPI()
 {
     static const double defaultDpi = 96;
+#if !USE(GTK4)
     GdkScreen* screen = gdk_screen_get_default();
-    if (!screen)
-        return defaultDpi;
+    if (screen) {
+        double dpi = gdk_screen_get_resolution(screen);
+        if (dpi != -1)
+            return dpi;
+    }
+#endif
 
-    double dpi = gdk_screen_get_resolution(screen);
-    if (dpi != -1)
-        return dpi;
+    static GtkSettings* gtkSettings = gtk_settings_get_default();
+    if (gtkSettings) {
+        int gtkXftDpi;
+        g_object_get(gtkSettings, "gtk-xft-dpi", &gtkXftDpi, nullptr);
+        return gtkXftDpi / 1024.0;
+    }
 
     static double cachedDpi = 0;
     if (cachedDpi)
@@ -105,8 +113,18 @@
         return cachedDpi;
 
     static const double millimetresPerInch = 25.4;
-    double diagonalInPixels = std::hypot(gdk_screen_get_width(screen), gdk_screen_get_height(screen));
-    double diagonalInInches = std::hypot(gdk_screen_get_width_mm(screen), gdk_screen_get_height_mm(screen)) / millimetresPerInch;
+
+    GdkDisplay* display = gdk_display_get_default();
+    if (!display)
+        return defaultDpi;
+    GdkMonitor* monitor = gdk_display_get_monitor(display, 0);
+    if (!monitor)
+        return defaultDpi;
+
+    GdkRectangle geometry;
+    gdk_monitor_get_geometry(monitor, &geometry);
+    double diagonalInPixels = std::hypot(geometry.width, geometry.height);
+    double diagonalInInches = std::hypot(gdk_monitor_get_width_mm(monitor), gdk_monitor_get_height_mm(monitor)) / millimetresPerInch;
     cachedDpi = diagonalInPixels / diagonalInInches;
 
     return cachedDpi;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to