xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #163: dummy-constant-dpi-v3.patch​

File dummy-constant-dpi-v3.patch​, 3.3 KB (added by Antoine Martin, 8 years ago)

patch which allows the xDPI and yDPI to be overriden via a root window property

Line 
1diff --git a/src/dummy.h b/src/dummy.h
2index c3fdd6e..7e7e0aa 100644
3--- a/src/dummy.h
4+++ b/src/dummy.h
5@@ -51,6 +51,7 @@ typedef struct dummyRec
6     /* options */
7     OptionInfoPtr Options;
8     Bool swCursor;
9+    Bool constantDPI;
10     /* proc pointer */
11     CloseScreenProcPtr CloseScreen;
12     xf86CursorInfoPtr CursorInfo;
13diff --git a/src/dummy_driver.c b/src/dummy_driver.c
14index 6062c39..f2cf290 100644
15--- a/src/dummy_driver.c
16+++ b/src/dummy_driver.c
17@@ -17,6 +17,12 @@
18 /* All drivers using the mi colormap manipulation need this */
19 #include "micmap.h"
20 
21+#ifdef RANDR
22+#include "randrstr.h"
23+#endif
24+
25+#include "windowstr.h"
26+
27 /* identifying atom needed by magnifiers */
28 #include <X11/Xatom.h>
29 #include "property.h"
30@@ -118,11 +124,15 @@ static SymTabRec DUMMYChipsets[] = {
31 };
32 
33 typedef enum {
34-    OPTION_SW_CURSOR
35+    OPTION_SW_CURSOR,
36+    OPTION_CONSTANT_DPI
37 } DUMMYOpts;
38 
39 static const OptionInfoRec DUMMYOptions[] = {
40     { OPTION_SW_CURSOR,        "SWcursor",     OPTV_BOOLEAN,   {0}, FALSE },
41+#ifdef RANDR
42+    { OPTION_CONSTANT_DPI,     "ConstantDPI",  OPTV_BOOLEAN,   {0}, FALSE },
43+#endif
44     { -1,                  NULL,           OPTV_NONE,  {0}, FALSE }
45 };
46 
47@@ -362,6 +372,7 @@ DUMMYPreInit(ScrnInfoPtr pScrn, int flags)
48     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, dPtr->Options);
49 
50     xf86GetOptValBool(dPtr->Options, OPTION_SW_CURSOR,&dPtr->swCursor);
51+    xf86GetOptValBool(dPtr->Options, OPTION_CONSTANT_DPI, &dPtr->constantDPI);
52 
53     if (device->videoRam != 0) {
54        pScrn->videoRam = device->videoRam;
55@@ -661,12 +672,49 @@ DUMMYScreenInit(SCREEN_INIT_ARGS_DECL)
56     return TRUE;
57 }
58 
59+const char *XDPY_PROPERTY = "dummy-constant-xdpi";
60+const char *YDPY_PROPERTY = "dummy-constant-ydpi";
61+static int get_constant_dpi_value(WindowPtr root, const char *property_name, int default_dpi)
62+{
63+    PropertyPtr prop;
64+       Atom type_atom = MakeAtom("CARDINAL", 8, TRUE);
65+       Atom prop_atom = MakeAtom(property_name, strlen(property_name), FALSE);
66+
67+    for (prop = wUserProps(root); prop; prop = prop->next) {
68+       if (prop->propertyName == prop_atom && prop->type == type_atom && prop->data) {
69+           //found it!
70+           int v = (int) (*((CARD32 *) prop->data));
71+           if ((v>0) && (v<4096)) {
72+               xf86DrvMsg(0, X_ERROR, "get_constant_dpi_value() found property \"%s\" with value=%i\n", property_name, (int) v);
73+               return (int) v;
74+           }
75+           break;
76+       }
77+    }
78+       return default_dpi;
79+}
80+
81 /* Mandatory */
82 Bool
83 DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL)
84 {
85     SCRN_INFO_PTR(arg);
86-    return dummyModeInit(pScrn, mode);
87+    if (!dummyModeInit(pScrn, mode))
88+        return FALSE;
89+#ifdef RANDR
90+    DUMMYPtr dPtr = DUMMYPTR(pScrn);
91+    if (dPtr->constantDPI) {
92+        int xDpi = get_constant_dpi_value(pScrn->pScreen->root, XDPY_PROPERTY, pScrn->xDpi);
93+        int yDpi = get_constant_dpi_value(pScrn->pScreen->root, YDPY_PROPERTY, pScrn->yDpi);
94+        //25.4 mm per inch: (254/10)
95+        pScrn->pScreen->mmWidth = mode->HDisplay * 254 / xDpi / 10;
96+        pScrn->pScreen->mmHeight = mode->VDisplay * 254 / yDpi / 10;
97+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "mm(dpi %ix%i)=%ix%i\n", xDpi, yDpi, pScrn->pScreen->mmWidth, pScrn->pScreen->mmHeight);
98+        RRScreenSizeNotify(pScrn->pScreen);
99+        RRTellChanged(pScrn->pScreen);
100+    }
101+#endif
102+    return TRUE;
103 }
104 
105 /* Mandatory */