From 33a200fa5b670a9e479e8d9be533ec1112867213 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Sat, 24 Sep 2011 18:46:29 +0200 Subject: [PATCH] Add option to set default DPI The default DPI can be either specified as fixed value or 'auto' meaning DDC is used when available. Based on patch by Nick Bowler --- hw/xfree86/common/xf86Config.c | 14 +++++++++++++- hw/xfree86/common/xf86Globals.c | 1 + hw/xfree86/common/xf86Helper.c | 4 ++++ hw/xfree86/common/xf86Privstr.h | 1 + hw/xfree86/man/xorg.conf.man | 6 ++++++ hw/xfree86/modes/xf86RandR12.c | 19 ++++++++++++++++++- 6 files changed, 43 insertions(+), 2 deletions(-) Index: xorg-server-1.10.4/hw/xfree86/common/xf86Config.c =================================================================== --- xorg-server-1.10.4.orig/hw/xfree86/common/xf86Config.c 2011-09-24 22:01:59.000000000 +0200 +++ xorg-server-1.10.4/hw/xfree86/common/xf86Config.c 2011-09-24 22:02:25.000000000 +0200 @@ -700,7 +700,8 @@ FLAG_AUTO_ENABLE_DEVICES, FLAG_GLX_VISUALS, FLAG_DRI2, - FLAG_USE_SIGIO + FLAG_USE_SIGIO, + FLAG_DEFAULT_DPI } FlagValues; /** @@ -762,6 +763,8 @@ {0}, FALSE }, { FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN, {0}, FALSE }, + { FLAG_DEFAULT_DPI, "DefaultDPI", OPTV_STRING, + {0}, FALSE }, { -1, NULL, OPTV_NONE, {0}, FALSE }, }; @@ -921,6 +924,15 @@ } } + + xf86Info.defaultDPI = DEFAULT_DPI; + if ((s = xf86GetOptValString(FlagOptions, FLAG_DEFAULT_DPI))) { + if (!xf86NameCmp(s, "auto")) { + xf86Info.defaultDPI = 0; + } else { + xf86Info.defaultDPI = strtoul(s, NULL, 0); + } + } #ifdef RANDR xf86Info.disableRandR = FALSE; xf86Info.randRFrom = X_DEFAULT; Index: xorg-server-1.10.4/hw/xfree86/common/xf86Globals.c =================================================================== --- xorg-server-1.10.4.orig/hw/xfree86/common/xf86Globals.c 2011-09-24 22:01:59.000000000 +0200 +++ xorg-server-1.10.4/hw/xfree86/common/xf86Globals.c 2011-09-24 22:02:25.000000000 +0200 @@ -105,6 +105,7 @@ .dontVTSwitch = FALSE, .dontZap = FALSE, .dontZoom = FALSE, + .defaultDPI = DEFAULT_DPI, .notrapSignals = FALSE, .caughtSignal = FALSE, .currentScreen = NULL, Index: xorg-server-1.10.4/hw/xfree86/common/xf86Helper.c =================================================================== --- xorg-server-1.10.4.orig/hw/xfree86/common/xf86Helper.c 2011-08-05 07:59:02.000000000 +0200 +++ xorg-server-1.10.4/hw/xfree86/common/xf86Helper.c 2011-09-24 22:02:25.000000000 +0200 @@ -956,10 +956,14 @@ } else { if (x > 0) pScrn->xDpi = x; + else if (xf86Info.defaultDPI) + pScrn->xDpi = xf86Info.defaultDPI; else pScrn->xDpi = DEFAULT_DPI; if (y > 0) pScrn->yDpi = y; + else if (xf86Info.defaultDPI) + pScrn->yDpi = xf86Info.defaultDPI; else pScrn->yDpi = DEFAULT_DPI; } Index: xorg-server-1.10.4/hw/xfree86/common/xf86Privstr.h =================================================================== --- xorg-server-1.10.4.orig/hw/xfree86/common/xf86Privstr.h 2011-07-16 22:18:32.000000000 +0200 +++ xorg-server-1.10.4/hw/xfree86/common/xf86Privstr.h 2011-09-24 22:02:25.000000000 +0200 @@ -68,6 +68,7 @@ Bool dontVTSwitch; Bool dontZap; Bool dontZoom; + unsigned defaultDPI; Bool notrapSignals; /* don't exit cleanly - die at fault */ Bool caughtSignal; Index: xorg-server-1.10.4/hw/xfree86/doc/man/xorg.conf.man =================================================================== --- xorg-server-1.10.4.orig/hw/xfree86/doc/man/xorg.conf.man 2011-09-24 22:01:59.000000000 +0200 +++ xorg-server-1.10.4/hw/xfree86/doc/man/xorg.conf.man 2011-09-24 22:02:25.000000000 +0200 @@ -544,6 +544,12 @@ and are passed to clients. Default: off. .TP 7 +.BI "Option \*qDefaultDPI\*q \*q" string \*q +This option allows to set a fixed DPI which is reported for all screens or the +special value \*qauto\*q which infers DPI from screen size read from DDC. The +fallback in case DDC reading fails is 96. +Default: 96. +.TP 7 .BI "Option \*qDisableVidModeExtension\*q \*q" boolean \*q This disables the parts of the VidMode extension used by the xvidtune client that can be used to change the video modes. Index: xorg-server-1.10.4/hw/xfree86/modes/xf86RandR12.c =================================================================== --- xorg-server-1.10.4.orig/hw/xfree86/modes/xf86RandR12.c 2011-09-24 22:01:59.000000000 +0200 +++ xorg-server-1.10.4/hw/xfree86/modes/xf86RandR12.c 2011-09-24 22:02:25.000000000 +0200 @@ -784,6 +784,7 @@ else { xf86OutputPtr output = xf86CompatOutput(pScrn); + xf86CrtcPtr crtc = output->crtc; if (output && output->conf_monitor && @@ -796,11 +797,27 @@ mmWidth = output->conf_monitor->mon_width; mmHeight = output->conf_monitor->mon_height; } - else + else if (!xf86Info.defaultDPI && crtc && crtc->mode.HDisplay && + output->mm_width && output->mm_height) + { + /* + * If the output has a mode and a declared size, use that + * to scale the screen size + */ + DisplayModePtr mode = &crtc->mode; + mmWidth = output->mm_width * width / mode->HDisplay; + mmHeight = output->mm_height * height / mode->VDisplay; + } + else if (xf86Info.defaultDPI) { /* * Otherwise, just set the screen to DEFAULT_DPI */ + mmWidth = width * 25.4 / xf86Info.defaultDPI; + mmHeight = height * 25.4 / xf86Info.defaultDPI; + } + else + { mmWidth = width * 25.4 / DEFAULT_DPI; mmHeight = height * 25.4 / DEFAULT_DPI; }