summarylogtreecommitdiffstats
path: root/0002-Constant-DPI.patch
blob: 1910fe025952f07139b0d3dae60134963fe579d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
diff --git a/src/dummy.h b/src/dummy.h
index 8e7c43b..8a4b3ad 100644
--- a/src/dummy.h
+++ b/src/dummy.h
@@ -41,6 +41,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 b4b42f7..408232a 100644
--- a/src/dummy_driver.c
+++ b/src/dummy_driver.c
@@ -17,6 +17,12 @@
 /* All drivers using the mi colormap manipulation need this */
 #include "micmap.h"
 
+#ifdef RANDR
+#include "randrstr.h"
+#endif
+
+#include "windowstr.h"
+
 /* identifying atom needed by magnifiers */
 #include <X11/Xatom.h>
 #include "property.h"
@@ -106,11 +112,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 }
 };
 
@@ -354,6 +364,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;
@@ -629,10 +640,45 @@ DUMMYScreenInit(SCREEN_INIT_ARGS_DECL)
     return TRUE;
 }
 
+const char *XDPY_PROPERTY = "dummy-constant-xdpi";
+const char *YDPY_PROPERTY = "dummy-constant-ydpi";
+static int get_dpi_value(WindowPtr root, const char *property_name, int default_dpi)
+{
+    PropertyPtr prop;
+    Atom type_atom = MakeAtom("CARDINAL", 8, TRUE);
+    Atom prop_atom = MakeAtom(property_name, strlen(property_name), FALSE);
+
+    for (prop = wUserProps(root); prop; prop = prop->next) {
+       if (prop->propertyName == prop_atom && prop->type == type_atom && prop->data) {
+           int v = (int) (*((CARD32 *) prop->data));
+           if ((v>0) && (v<4096)) {
+               xf86DrvMsg(0, X_INFO, "get_constant_dpi_value() found property \"%s\" with value=%i\n", property_name, (int) v);
+               return (int) v;
+           }
+           break;
+       }
+    }
+    return default_dpi;
+}
+
 /* Mandatory */
 Bool
 DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL)
 {
+    SCRN_INFO_PTR(arg);
+#ifdef RANDR
+    DUMMYPtr dPtr = DUMMYPTR(pScrn);
+    if (dPtr->constantDPI) {
+        int xDpi = get_dpi_value(pScrn->pScreen->root, XDPY_PROPERTY, pScrn->xDpi);
+        int yDpi = get_dpi_value(pScrn->pScreen->root, YDPY_PROPERTY, pScrn->yDpi);
+        //25.4 mm per inch: (254/10)
+        pScrn->pScreen->mmWidth = mode->HDisplay * 254 / xDpi / 10;
+        pScrn->pScreen->mmHeight = mode->VDisplay * 254 / yDpi / 10;
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "mm(dpi %ix%i)=%ix%i\n", xDpi, yDpi, pScrn->pScreen->mmWidth, pScrn->pScreen->mmHeight);
+        RRScreenSizeNotify(pScrn->pScreen);
+        RRTellChanged(pScrn->pScreen);
+    }
+#endif
     return TRUE;
 }