Hello all.

I recently got a HiDPI monitor (15" at 3200x1800, 234 dpi) and I noticed that 
Firefox (32) doesn't automatically scale UI/content to take advantage of the 
hidpi, with the result that stuff renders uncomfortably small by default. If I 
manually set devPixelsPerPx to 2, I seem to get a reasonable UI and content 
scaling.

I've perused the source code and did a little bit of debugging, and while the 
DPI is detected correctly (nsWindow::GetDPI returns 234), no scaling factor is 
set from this. I've tracked this to the fact that nsWindow in Linux does not 
reimplement GetDefaultScaleInternal().

Since the patch to implement this is rather trivial, I'm attaching a 
preliminary version to this post. Still, I was wondering: was the omission 
intentional (e.g. because other means should be used on Linux for this, and I 
just happen to have a set-up where this is not detected)?

Best regards,

Giuseppe "Oblomov" Bilotta


P.S. Patch inlined using web interface, sorry for the word wrap, will post it 
better if necessary

-- 

>From acc0a97139dbed9049c9bfd74716dee2e4633d1d Mon Sep 17 00:00:00 2001
From: Giuseppe Bilotta <giuseppe.bilo...@gmail.com>
Date: Fri, 10 Oct 2014 00:09:42 +0200
Subject: [PATCH] Automatically set pixel ratio for HiDPI on Linux

Set the device to CSS pixel ratio to the closest integer by which the
true DPI divides the CSS virtual 96dpi.
---
 widget/gtk/nsWindow.cpp | 10 ++++++++++
 widget/gtk/nsWindow.h   |  1 +
 2 files changed, 11 insertions(+)

diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp
index 2734f84..aef146f 100644
--- a/widget/gtk/nsWindow.cpp
+++ b/widget/gtk/nsWindow.cpp
@@ -729,6 +729,16 @@ nsWindow::GetDPI()
     return float(DisplayHeight(dpy, defaultScreen)/heightInches);
 }
 
+double
+nsWindow::GetDefaultScaleInternal()
+{
+    // We want to set the default CSS to device pixel ratio as the
+    // closest _integer_ multiple, so round the ratio of actual dpi
+    // to CSS dpi (96)
+    float dpi = GetDPI();
+    return round(dpi/96.0);
+}
+
 NS_IMETHODIMP
 nsWindow::SetParent(nsIWidget *aNewParent)
 {
diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h
index cd4bd9c..79a4430 100644
--- a/widget/gtk/nsWindow.h
+++ b/widget/gtk/nsWindow.h
@@ -97,6 +97,7 @@ public:
     NS_IMETHOD         Destroy(void);
     virtual nsIWidget *GetParent();
     virtual float      GetDPI();
+    virtual double     GetDefaultScaleInternal();
     virtual nsresult   SetParent(nsIWidget* aNewParent);
     NS_IMETHOD         SetModal(bool aModal);
     virtual bool       IsVisible() const;
-- 
2.1.0.255.gcd10c46

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to