[PATCH xf86-video-dummy] "ConstantDPI" option

Antoine Martin antoine at nagafix.co.uk
Tue Apr 15 07:32:15 PDT 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

This patch allows us to ensure that when the dummy driver resolution is
changed via RandR, the "physical" screen dimensions is resized
accordingly so that the DPI remains constant.
It fixes applications that ignore "Xft.dpi" and calculate their own DPI
value based on the screen dimensions (ie: Java does this).
It adds a new boolean option to the dummy driver named "ConstantDPI",
which defaults to False. (this ensures that existing setups running with
dummy will continue to have very strange DPI values by default as before...)
An alternative would be to look at the "DisplaySize" option and only
keep the DPI constant if it was unspecified. But this seemed a little
bit too obscure to figure out for users.

I would also like to add the ability to tweak this DPI value at runtime:
in the context of xpra, the desired DPI may need to change every time a
new client connects to the session, so the "-dpi" switch is not sufficient.
So I was thinking of allowing a root window property to override the
global default DPI value. Does this sound reasonable? ("dummy-dpi"?)

Then, unless there are any objections, I may also take a stab at adding
RandR 1.2 based on this patch for Xvfb:
http://patchwork.freedesktop.org/patch/13852/
Again, this could be disabled by default if needed.

And whilst I am here, would a whitespace cleanup patch be accepted for
the dummy driver?
I know it messes up the diff history somewhat, but I loaded the main
file in an IDE that didn't use 8 characters per tab and the result was
not pretty:
* it mixes tabs and spaces, sometimes on the same line..
* often uses 4 character indentation, but in some places just 4+2...
FWIW: my patch doesn't make it worse!

Cheers
Antoine

Signed-off-by: Antoine Martin <antoine at devloop.org.uk>

diff --git a/src/dummy.h b/src/dummy.h
index c3fdd6e..7e7e0aa 100644
- --- a/src/dummy.h
+++ b/src/dummy.h
@@ -51,6 +51,7 @@ typedef struct dummyRec
     /* options */
     OptionInfoPtr Options;
     Bool swCursor;
+    Bool constantDPI;
     /* proc pointer */
     CloseScreenProcPtr CloseScreen;
     xf86CursorInfoPtr CursorInfo;
diff --git a/src/dummy_driver.c b/src/dummy_driver.c
index 6062c39..8b85fb1 100644
- --- a/src/dummy_driver.c
+++ b/src/dummy_driver.c
@@ -17,6 +17,10 @@
 /* All drivers using the mi colormap manipulation need this */
 #include "micmap.h"
 
+#ifdef RANDR
+#include "randrstr.h"
+#endif
+
 /* identifying atom needed by magnifiers */
 #include <X11/Xatom.h>
 #include "property.h"
@@ -118,11 +122,15 @@ static SymTabRec DUMMYChipsets[] = {
 };
 
 typedef enum {
- -    OPTION_SW_CURSOR
+    OPTION_SW_CURSOR,
+    OPTION_CONSTANT_DPI
 } DUMMYOpts;
 
 static const OptionInfoRec DUMMYOptions[] = {
     { OPTION_SW_CURSOR,    "SWcursor",    OPTV_BOOLEAN,    {0}, FALSE },
+#ifdef RANDR
+    { OPTION_CONSTANT_DPI,    "ConstantDPI",    OPTV_BOOLEAN,    {0},
FALSE },
+#endif
     { -1,                  NULL,           OPTV_NONE,    {0}, FALSE }
 };
 
@@ -362,6 +370,7 @@ DUMMYPreInit(ScrnInfoPtr pScrn, int flags)
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, dPtr->Options);
 
     xf86GetOptValBool(dPtr->Options, OPTION_SW_CURSOR,&dPtr->swCursor);
+    xf86GetOptValBool(dPtr->Options, OPTION_CONSTANT_DPI,
&dPtr->constantDPI);
 
     if (device->videoRam != 0) {
     pScrn->videoRam = device->videoRam;
@@ -666,7 +675,20 @@ Bool
 DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL)
 {
     SCRN_INFO_PTR(arg);
- -    return dummyModeInit(pScrn, mode);
+    if (!dummyModeInit(pScrn, mode))
+        return FALSE;
+#ifdef RANDR
+    DUMMYPtr dPtr = DUMMYPTR(pScrn);
+    if (dPtr->constantDPI) {
+        //25.4 mm per inch: (254/10)
+        pScrn->pScreen->mmWidth = mode->HDisplay * 254 / pScrn->xDpi / 10;
+        pScrn->pScreen->mmHeight = mode->VDisplay * 254 / pScrn->yDpi / 10;
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "mm(dpi %ix%i)=%ix%i",
pScrn->xDpi, pScrn->yDpi, pScrn->pScreen->mmWidth,
pScrn->pScreen->mmHeight);
+        RRScreenSizeNotify(pScrn->pScreen);
+        RRTellChanged(pScrn->pScreen);
+    }
+#endif
+    return TRUE;
 }
 
 /* Mandatory */
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlNNQu8ACgkQGK2zHPGK1rtkAgCfRVqqlvYZTZDzB9svU1gdy2ao
BCcAnAqmsxmfk1MG+wT0zfeBOW8px/7+
=xTD6
-----END PGP SIGNATURE-----



More information about the xorg-devel mailing list