Skip to content
Draft
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
Binary file added .nuget/nuget.exe
Binary file not shown.
89 changes: 86 additions & 3 deletions vibrance.GUI/AMD/AmdDynamicVibranceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,88 @@ public void SetNeverChangeColorSettings(bool neverChangeColorSettings)
_vibranceInfo.neverChangeColorSettings = neverChangeColorSettings;
}

public void SetProfileToggleEnabled(bool profileToggleEnabled)
{
_vibranceInfo.isProfileToggleEnabled = profileToggleEnabled;
_vibranceInfo.isProfileToggleOn = true;
}

public void SetProfileToggleState(bool isProfileToggleOn)
{
_vibranceInfo.isProfileToggleOn = isProfileToggleOn;
}

public bool IsProfileToggleEnabled()
{
return _vibranceInfo.isProfileToggleEnabled;
}

public bool IsProfileToggleOn()
{
return _vibranceInfo.isProfileToggleOn;
}

public void ApplyProfileToggle(IntPtr windowHandle, string processName, bool isProfileToggleOn)
{
if (_applicationSettings.Count == 0)
{
return;
}

ApplicationSetting applicationSetting = _applicationSettings.FirstOrDefault(x => string.Equals(x.Name, processName, StringComparison.OrdinalIgnoreCase));
if (applicationSetting == null)
{
return;
}

Screen screen = Screen.FromHandle(windowHandle);
if (screen == null)
{
return;
}

_gameScreen = screen;

if (isProfileToggleOn)
{
if (_vibranceInfo.userVibranceSettingDefault != applicationSetting.IngameLevel)
{
if (_vibranceInfo.affectPrimaryMonitorOnly)
{
_amdAdapter.SetSaturationOnDisplay(applicationSetting.IngameLevel, screen.DeviceName);
}
else
{
_amdAdapter.SetSaturationOnAllDisplays(applicationSetting.IngameLevel);
}
}

if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
DeviceGammaRampHelper.IsGammaRampEqualToWindowsValues(_vibranceInfo, applicationSetting) == false)
{
DeviceGammaRampHelper.SetGammaRamp(screen, applicationSetting.Gamma, applicationSetting.Brightness, applicationSetting.Contrast);
_vibranceInfo.isColorSettingApplied = true;
}
}
else
{
_amdAdapter.SetSaturationOnAllDisplays(_vibranceInfo.userVibranceSettingDefault);

if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == true)
{
if (_vibranceInfo.affectPrimaryMonitorOnly && _gameScreen != null && _gameScreen.DeviceName.Equals(screen.DeviceName))
{
DeviceGammaRampHelper.SetGammaRamp(_gameScreen, _vibranceInfo.userColorSettings.brightness, _vibranceInfo.userColorSettings.contrast, _vibranceInfo.userColorSettings.gamma);
}
else
{
Screen.AllScreens.ToList().ForEach(currentScreen => DeviceGammaRampHelper.SetGammaRamp(currentScreen, _vibranceInfo.userColorSettings.brightness, _vibranceInfo.userColorSettings.contrast, _vibranceInfo.userColorSettings.gamma));
}
_vibranceInfo.isColorSettingApplied = false;
}
}
}

public void SetWindowsColorSettings(int brightness, int contrast, int gamma)
{
_vibranceInfo.userColorSettings.brightness = brightness;
Expand Down Expand Up @@ -158,14 +240,15 @@ private void OnWinEventHook(object sender, WinEventHookEventArgs e)
{
if (_applicationSettings.Count > 0)
{
bool shouldApplyProfileSettings = !_vibranceInfo.isProfileToggleEnabled || _vibranceInfo.isProfileToggleOn;
ApplicationSetting applicationSetting = _applicationSettings.FirstOrDefault(x => string.Equals(x.Name, e.ProcessName, StringComparison.OrdinalIgnoreCase));
if (applicationSetting != null)
{
Screen screen = Screen.FromHandle(e.Handle);
_gameScreen = screen;

//apply application specific saturation
if (_vibranceInfo.userVibranceSettingDefault != applicationSetting.IngameLevel)
if (shouldApplyProfileSettings && _vibranceInfo.userVibranceSettingDefault != applicationSetting.IngameLevel)
{
if (_vibranceInfo.affectPrimaryMonitorOnly)
{
Expand All @@ -188,7 +271,7 @@ private void OnWinEventHook(object sender, WinEventHookEventArgs e)
}

//test if color settings change is needed
if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
if (shouldApplyProfileSettings && _vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
DeviceGammaRampHelper.IsGammaRampEqualToWindowsValues(_vibranceInfo, applicationSetting) == false)
{
DeviceGammaRampHelper.SetGammaRamp(screen, applicationSetting.Gamma, applicationSetting.Brightness, applicationSetting.Contrast);
Expand Down Expand Up @@ -247,4 +330,4 @@ private static void PerformResolutionChange(Screen screen, ResolutionModeWrapper
ResolutionHelper.ChangeResolutionEx(resolutionSettings, screen.DeviceName);
}
}
}
}
98 changes: 96 additions & 2 deletions vibrance.GUI/NVIDIA/NvidiaDynamicVibranceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ private static void OnWinEventHook(object sender, WinEventHookEventArgs e)
{
if (_applicationSettings.Count > 0)
{
bool shouldApplyProfileSettings = !_vibranceInfo.isProfileToggleEnabled || _vibranceInfo.isProfileToggleOn;
ApplicationSetting applicationSetting = _applicationSettings.FirstOrDefault(x => string.Equals(x.Name, e.ProcessName, StringComparison.OrdinalIgnoreCase));
if (applicationSetting != null)
{
Expand All @@ -206,7 +207,7 @@ private static void OnWinEventHook(object sender, WinEventHookEventArgs e)
_gameScreen = screen;

//test if digital vibrance change is needed
if (!equalsDVCLevel(displayHandle, applicationSetting.IngameLevel))
if (shouldApplyProfileSettings && !equalsDVCLevel(displayHandle, applicationSetting.IngameLevel))
{
_vibranceInfo.defaultHandle = displayHandle;
setDVCLevel(_vibranceInfo.defaultHandle, applicationSetting.IngameLevel);
Expand All @@ -223,7 +224,7 @@ private static void OnWinEventHook(object sender, WinEventHookEventArgs e)
}

//test if color settings change is needed
if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
if (shouldApplyProfileSettings && _vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
DeviceGammaRampHelper.IsGammaRampEqualToWindowsValues(_vibranceInfo, applicationSetting) == false)
{
DeviceGammaRampHelper.SetGammaRamp(screen, applicationSetting.Gamma, applicationSetting.Brightness, applicationSetting.Contrast);
Expand Down Expand Up @@ -345,6 +346,99 @@ public void SetNeverChangeColorSettings(bool neverChangeColorSettings)
_vibranceInfo.neverChangeColorSettings = neverChangeColorSettings;
}

public void SetProfileToggleEnabled(bool profileToggleEnabled)
{
_vibranceInfo.isProfileToggleEnabled = profileToggleEnabled;
_vibranceInfo.isProfileToggleOn = true;
}

public void SetProfileToggleState(bool isProfileToggleOn)
{
_vibranceInfo.isProfileToggleOn = isProfileToggleOn;
}

public bool IsProfileToggleEnabled()
{
return _vibranceInfo.isProfileToggleEnabled;
}

public bool IsProfileToggleOn()
{
return _vibranceInfo.isProfileToggleOn;
}

public void ApplyProfileToggle(IntPtr windowHandle, string processName, bool isProfileToggleOn)
{
if (_applicationSettings.Count == 0)
{
return;
}

ApplicationSetting applicationSetting = _applicationSettings.FirstOrDefault(x => string.Equals(x.Name, processName, StringComparison.OrdinalIgnoreCase));
if (applicationSetting == null)
{
return;
}

int displayHandle = GetApplicationDisplayHandle(windowHandle);
if (displayHandle == -1)
{
return;
}

Screen screen = Screen.FromHandle(windowHandle);
if (screen == null)
{
return;
}

_gameScreen = screen;

if (isProfileToggleOn)
{
if (!equalsDVCLevel(displayHandle, applicationSetting.IngameLevel))
{
_vibranceInfo.defaultHandle = displayHandle;
setDVCLevel(_vibranceInfo.defaultHandle, applicationSetting.IngameLevel);
}

if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == false &&
DeviceGammaRampHelper.IsGammaRampEqualToWindowsValues(_vibranceInfo, applicationSetting) == false)
{
DeviceGammaRampHelper.SetGammaRamp(screen, applicationSetting.Gamma, applicationSetting.Brightness, applicationSetting.Contrast);
_vibranceInfo.isColorSettingApplied = true;
}
}
else
{
if (_vibranceInfo.affectPrimaryMonitorOnly && !equalsDVCLevel(_vibranceInfo.defaultHandle, _vibranceInfo.userVibranceSettingDefault))
{
if (_gameScreen != null && !_gameScreen.DeviceName.Equals(screen.DeviceName))
{
return;
}
setDVCLevel(_vibranceInfo.defaultHandle, _vibranceInfo.userVibranceSettingDefault);
}
else if (!_vibranceInfo.affectPrimaryMonitorOnly && !_vibranceInfo.displayHandles.TrueForAll(handle => equalsDVCLevel(handle, _vibranceInfo.userVibranceSettingDefault)))
{
_vibranceInfo.displayHandles.ForEach(handle => setDVCLevel(handle, _vibranceInfo.userVibranceSettingDefault));
}

if (_vibranceInfo.neverChangeColorSettings == false && _vibranceInfo.isColorSettingApplied == true)
{
if (_vibranceInfo.affectPrimaryMonitorOnly && _gameScreen != null && _gameScreen.DeviceName.Equals(screen.DeviceName))
{
DeviceGammaRampHelper.SetGammaRamp(_gameScreen, _vibranceInfo.userColorSettings.brightness, _vibranceInfo.userColorSettings.contrast, _vibranceInfo.userColorSettings.gamma);
}
else
{
Screen.AllScreens.ToList().ForEach(currentScreen => DeviceGammaRampHelper.SetGammaRamp(currentScreen, _vibranceInfo.userColorSettings.brightness, _vibranceInfo.userColorSettings.contrast, _vibranceInfo.userColorSettings.gamma));
}
_vibranceInfo.isColorSettingApplied = false;
}
}
}

public void SetWindowsColorSettings(int brightness, int contrast, int gamma)
{
_vibranceInfo.userColorSettings.brightness = brightness;
Expand Down
2 changes: 2 additions & 0 deletions vibrance.GUI/common/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public struct VibranceInfo
public bool affectPrimaryMonitorOnly;
public bool neverChangeResolution;
public bool neverChangeColorSettings;
public bool isProfileToggleEnabled;
public bool isProfileToggleOn;
public bool isColorSettingApplied;
public bool isResolutionChangeApplied;
public ColorSettings userColorSettings;
Expand Down
7 changes: 4 additions & 3 deletions vibrance.GUI/common/ISettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace vibrance.GUI.common
internal interface ISettingsController
{
bool SetVibranceSettings(string windowsLevel, string affectPrimaryMonitorOnly, string neverSwitchResolution, string neverChangeColorSettings, List<ApplicationSetting> applicationSettings,
string brightnessWindowsLevel, string contrastWindowsLevel, string gammaWindowsLevel);
string brightnessWindowsLevel, string contrastWindowsLevel, string gammaWindowsLevel, string profileToggleEnabled, string profileToggleHotkey, string profileToggleState);
bool SetVibranceSetting(string szKeyName, string value);
void ReadVibranceSettings(GraphicsAdapter graphicsAdapter, out int vibranceWindowsLevel, out bool affectPrimaryMonitorOnly, out bool neverSwitchResolution,
out bool neverChangeColorSettings, out List<ApplicationSetting> applicationSettings, out int brightnessWindowsLevel, out int contrastWindowsLevel, out int gammaWindowsLevel);
out bool neverChangeColorSettings, out List<ApplicationSetting> applicationSettings, out int brightnessWindowsLevel, out int contrastWindowsLevel, out int gammaWindowsLevel,
out bool profileToggleEnabled, out string profileToggleHotkey, out bool profileToggleState);
}
}
}
7 changes: 6 additions & 1 deletion vibrance.GUI/common/IVibranceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ public interface IVibranceProxy
void SetNeverSwitchResolution(bool neverSwitchResolution);
void SetNeverChangeColorSettings(bool neverChangeColorSettings);
void SetWindowsColorSettings(int brightness, int contrast, int gamma);
void SetProfileToggleEnabled(bool profileToggleEnabled);
void SetProfileToggleState(bool isProfileToggleOn);
bool IsProfileToggleEnabled();
bool IsProfileToggleOn();
void ApplyProfileToggle(IntPtr windowHandle, string processName, bool isProfileToggleOn);

void SetWindowsColorBrightness(int brightness);
void SetWindowsColorContrast(int contrast);
void SetWindowsColorGamma(int gamma);
}
}
}
Loading