Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/features/test_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ def test_identify_getramp_fails():
assert identify_display(r"\\.\DISPLAY1") is False


def test_identify_flash_fails():
from winrandr.features.gamma import identify_display

with patch("winrandr.features.gamma._CreateDCW", return_value=0x1234):
with patch("winrandr.features.gamma._GetDeviceGammaRamp", return_value=1):
with patch("winrandr.features.gamma._SetDeviceGammaRamp", side_effect=[0, 1]):
with patch("winrandr.features.gamma._DeleteDC"):
with patch("winrandr.features.gamma.time.sleep"):
assert identify_display(r"\\.\DISPLAY1") is False


def test_identify_blank_fails():
from winrandr.features.gamma import identify_display

with patch("winrandr.features.gamma._CreateDCW", return_value=0x1234):
with patch("winrandr.features.gamma._GetDeviceGammaRamp", return_value=1):
with patch("winrandr.features.gamma._SetDeviceGammaRamp", side_effect=[1, 0, 1]):
with patch("winrandr.features.gamma._DeleteDC"):
with patch("winrandr.features.gamma.time.sleep"):
assert identify_display(r"\\.\DISPLAY1") is False


def test_identify_exception():
from winrandr.features.gamma import identify_display

Expand Down
13 changes: 10 additions & 3 deletions winrandr/features/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def identify_display(device_name: str, duration: float = 2.0) -> bool:
return False

saved = (c_uint16 * (3 * 256))()
all_ok = True
try:
ramp = (c_uint16 * (3 * 256))()
if not _GetDeviceGammaRamp(dc, ramp):
Expand All @@ -102,11 +103,17 @@ def identify_display(device_name: str, duration: float = 2.0) -> bool:

interval = duration / 6
for _ in range(3):
_SetDeviceGammaRamp(dc, flash)
if not _SetDeviceGammaRamp(dc, flash):
logger.warning("设置 %s 闪烁白屏失败(伽马写入被拒绝)", device_name)
all_ok = False
break
time.sleep(interval)
_SetDeviceGammaRamp(dc, blank)
if not _SetDeviceGammaRamp(dc, blank):
logger.warning("设置 %s 闪烁黑屏失败(伽马写入被拒绝)", device_name)
all_ok = False
break
time.sleep(interval)
finally:
_SetDeviceGammaRamp(dc, saved)
_DeleteDC(dc)
return True
return all_ok
Loading