Skip to content

Commit

Permalink
Add warning to disable extended display mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed Dec 18, 2020
1 parent 7587e25 commit fd2b723
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
6 changes: 4 additions & 2 deletions INSTALL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
2. Right click on CS:GO and go to properties.
3. Click *Set launch options...* and add `-nogammaramp`.
4. Run `unlock_gamma_range.reg` and restart PC. (Windows only)
5. Set your preferred `mat_monitorgamma` and `mat_monitorgamma_tv_enabled`
5. If you have multiple monitors configured with `Extend these displays`,
you might need to turn off all but the primary monitor. (Windows only)
6. Set your preferred `mat_monitorgamma` and `mat_monitorgamma_tv_enabled`
in `settings.ini`.
6. f.lux and Redshift are not compatible: you have to disable both! It runs
7. f.lux and Redshift are not compatible: you have to disable both! It runs
perfectly with Windows Night Light though.


Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.1
0.5.2
33 changes: 17 additions & 16 deletions gamma/context_wingdi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import contextmanager
from ctypes import byref, sizeof, Structure, windll, WinError
from ctypes import byref, sizeof, Structure, windll
from ctypes import create_unicode_buffer, POINTER
from ctypes.wintypes import DWORD, HDC, WCHAR, WORD
from winreg import (HKEY_LOCAL_MACHINE, OpenKeyEx, CloseKey, QueryValueEx,
Expand Down Expand Up @@ -71,7 +71,6 @@ def __init__(self, *args, **kwargs):
while EnumDisplayDevices(None, device_num, byref(device), 0):
if device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE:
device_name = device.DeviceName
break

device_num += 1

Expand All @@ -82,27 +81,32 @@ def __init__(self, *args, **kwargs):
self._hdc = hdc

if not hdc:
raise ContextError('Unable to create device context') \
from WinError()
raise ContextError('Unable to create device context')

cmcap = GetDeviceCaps(hdc, COLORMGMTCAPS)

if not cmcap & CM_GAMMA_RAMP:
self._hdc = None

if not DeleteDC(hdc):
raise ContextError('Unable to delete device context') \
from WinError()
raise ContextError('Unable to delete device context')

del hdc
self._hdc = None

try:
with self._get_dc() as hdc:
cmcap = GetDeviceCaps(hdc, COLORMGMTCAPS)

if not cmcap & CM_GAMMA_RAMP:
raise ContextError('Display device does not support gamma '
'ramps') from WinError()

'ramps')

if not GetDeviceGammaRamp(hdc, byref((WORD * 256 * 3)())):
if device_num > 1:
raise ContextError('Unable to modify gamma ramp; turn '
'off all monitors except your primary')
else:
raise ContextError('Unable to modify gamma ramp')
try:
key = None
key = OpenKeyEx(HKEY_LOCAL_MACHINE, ICM_KEY, access=KEY_READ |
Expand Down Expand Up @@ -148,8 +152,7 @@ def get_ramp(self):
ramp = (WORD * 256 * 3)()

if not GetDeviceGammaRamp(hdc, byref(ramp)):
raise ContextError('Unable to get gamma ramp') \
from WinError()
raise ContextError('Unable to get gamma ramp')

return [[ramp[i][j] / 65535 for j in range(256)] for i in range(3)]

Expand All @@ -163,7 +166,7 @@ def set_ramp(self, ramp):
with self._get_dc() as hdc:
if not SetDeviceGammaRamp(hdc, byref(_ramp)):
raise ContextError('Unable to set gamma ramp; has the gamma '
'range been unlocked yet?') from WinError()
'range been unlocked yet?')

def close(self):
try:
Expand Down Expand Up @@ -196,10 +199,8 @@ def close(self):
ramp[i][j] = j << 8

if not SetDeviceGammaRamp(hdc, byref(ramp)):
raise ContextError('Unable to restore gamma ramp') \
from WinError()
raise ContextError('Unable to restore gamma ramp')
finally:
if self._hdc is not None:
if not DeleteDC(self._hdc):
raise ContextError('Unable to delete device context') \
from WinError()
raise ContextError('Unable to delete device context')

0 comments on commit fd2b723

Please sign in to comment.