|
| 1 | +# A part of NonVisual Desktop Access (NVDA) |
| 2 | +# This file is covered by the GNU General Public License. |
| 3 | +# See the file COPYING for more details. |
| 4 | +# Copyright (C) 2018-2019 NV Access Limited, Babbage B.V., Leonard de Ruijter |
| 5 | + |
| 6 | +"""Screen curtain implementation based on the windows magnification API. |
| 7 | +This implementation only works on Windows 8 and above. |
| 8 | +""" |
| 9 | + |
| 10 | +import vision |
| 11 | +import winVersion |
| 12 | +from ctypes import Structure, windll, c_float, POINTER, WINFUNCTYPE, WinError |
| 13 | +from ctypes.wintypes import BOOL |
| 14 | + |
| 15 | + |
| 16 | +class MAGCOLOREFFECT(Structure): |
| 17 | + _fields_ = (("transform", c_float * 5 * 5),) |
| 18 | + |
| 19 | + |
| 20 | +TRANSFORM_BLACK = MAGCOLOREFFECT() |
| 21 | +TRANSFORM_BLACK.transform[4][4] = 1.0 |
| 22 | + |
| 23 | + |
| 24 | +def _errCheck(result, func, args): |
| 25 | + if result == 0: |
| 26 | + raise WinError() |
| 27 | + return args |
| 28 | + |
| 29 | + |
| 30 | +class Magnification: |
| 31 | + """Singleton that wraps necessary functions from the Windows magnification API.""" |
| 32 | + |
| 33 | + _magnification = windll.Magnification |
| 34 | + |
| 35 | + _MagInitializeFuncType = WINFUNCTYPE(BOOL) |
| 36 | + _MagUninitializeFuncType = WINFUNCTYPE(BOOL) |
| 37 | + _MagSetFullscreenColorEffectFuncType = WINFUNCTYPE(BOOL, POINTER(MAGCOLOREFFECT)) |
| 38 | + _MagSetFullscreenColorEffectArgTypes = ((1, "effect"),) |
| 39 | + _MagGetFullscreenColorEffectFuncType = WINFUNCTYPE(BOOL, POINTER(MAGCOLOREFFECT)) |
| 40 | + _MagGetFullscreenColorEffectArgTypes = ((2, "effect"),) |
| 41 | + |
| 42 | + MagInitialize = _MagInitializeFuncType(("MagInitialize", _magnification)) |
| 43 | + MagInitialize.errcheck = _errCheck |
| 44 | + MagUninitialize = _MagUninitializeFuncType(("MagUninitialize", _magnification)) |
| 45 | + MagUninitialize.errcheck = _errCheck |
| 46 | + try: |
| 47 | + MagSetFullscreenColorEffect = _MagSetFullscreenColorEffectFuncType( |
| 48 | + ("MagSetFullscreenColorEffect", _magnification), |
| 49 | + _MagSetFullscreenColorEffectArgTypes |
| 50 | + ) |
| 51 | + MagSetFullscreenColorEffect.errcheck = _errCheck |
| 52 | + MagGetFullscreenColorEffect = _MagGetFullscreenColorEffectFuncType( |
| 53 | + ("MagGetFullscreenColorEffect", _magnification), |
| 54 | + _MagGetFullscreenColorEffectArgTypes |
| 55 | + ) |
| 56 | + MagGetFullscreenColorEffect.errcheck = _errCheck |
| 57 | + except AttributeError: |
| 58 | + MagSetFullscreenColorEffect = None |
| 59 | + MagGetFullscreenColorEffect = None |
| 60 | + |
| 61 | + |
| 62 | +class VisionEnhancementProvider(vision.providerBase.VisionEnhancementProvider): |
| 63 | + name = "screenCurtain" |
| 64 | + # Translators: Description of a vision enhancement provider that disables output to the screen, |
| 65 | + # making it black. |
| 66 | + description = _("Screen Curtain") |
| 67 | + supportedRoles = frozenset([vision.constants.Role.COLORENHANCER]) |
| 68 | + |
| 69 | + @classmethod |
| 70 | + def canStart(cls): |
| 71 | + return winVersion.isFullScreenMagnificationAvailable() |
| 72 | + |
| 73 | + def __init__(self): |
| 74 | + super(VisionEnhancementProvider, self).__init__() |
| 75 | + Magnification.MagInitialize() |
| 76 | + Magnification.MagSetFullscreenColorEffect(TRANSFORM_BLACK) |
| 77 | + |
| 78 | + def terminate(self): |
| 79 | + super(VisionEnhancementProvider, self).terminate() |
| 80 | + Magnification.MagUninitialize() |
| 81 | + |
| 82 | + def registerEventExtensionPoints(self, extensionPoints): |
| 83 | + # The screen curtain isn't interested in any events |
| 84 | + pass |
0 commit comments