mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Reduces config scanning delay as much as possible
WinLibrary currently waits 5 seconds if it can't read the taskbar registry, and then it tries again. This is because based on my testing, if a screen layout changes, windows takes up to 20 seconds to update registry to record this fact. We have to wait until windows has finished 4 times before we are sure to have passed the 20 second window. This is likely the delay you have mentioned. I *think* that I can slightly speed this up. We only MUST to do this delay when we are recording the config (i.e. creating a new display profile), and other times it's kind of a nice to have. So I've attempted to speed this up using a 'fastScan' option for the WinLibrary GetActiveConfig function. This will enable it to only query once for the general scans of the active config, and if there is a problem getting the data it will just accept that fact and will still return quickly. But it will still take up to 20 seconds when creating a new display profile as it is REALLY important we get that data correctly. Fixes #129
This commit is contained in:
parent
010c8c33b2
commit
83b8938e1a
@ -26,8 +26,8 @@ using System.Resources;
|
|||||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||||
|
|
||||||
// Version information
|
// Version information
|
||||||
[assembly: AssemblyVersion("2.4.1.1")]
|
[assembly: AssemblyVersion("2.4.1.2")]
|
||||||
[assembly: AssemblyFileVersion("2.4.1.1")]
|
[assembly: AssemblyFileVersion("2.4.1.2")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|
||||||
|
@ -548,7 +548,7 @@ namespace DisplayMagician.UIForms
|
|||||||
// Refresh the profiles to see whats valid
|
// Refresh the profiles to see whats valid
|
||||||
ProfileRepository.IsPossibleRefresh();
|
ProfileRepository.IsPossibleRefresh();
|
||||||
// Reload the profiles in case we swapped to another program to change it
|
// Reload the profiles in case we swapped to another program to change it
|
||||||
ProfileRepository.UpdateActiveProfile();
|
ProfileRepository.UpdateActiveProfile(false);
|
||||||
// Change to the current selected Profile
|
// Change to the current selected Profile
|
||||||
ChangeSelectedProfile(ProfileRepository.GetActiveProfile());
|
ChangeSelectedProfile(ProfileRepository.GetActiveProfile());
|
||||||
// Refresh the Profile UI
|
// Refresh the Profile UI
|
||||||
|
@ -478,7 +478,7 @@ namespace DisplayMagicianShared
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool CreateProfileFromCurrentDisplaySettings()
|
public bool CreateProfileFromCurrentDisplaySettings(bool fastScan = true)
|
||||||
{
|
{
|
||||||
// Calling the 3 different libraries automatically gets the different configs from each of the 3 video libraries.
|
// Calling the 3 different libraries automatically gets the different configs from each of the 3 video libraries.
|
||||||
// If the video library isn't in use then it also fills in the defaults so that the JSON file can save properly
|
// If the video library isn't in use then it also fills in the defaults so that the JSON file can save properly
|
||||||
@ -495,16 +495,16 @@ namespace DisplayMagicianShared
|
|||||||
if (VideoMode == VIDEO_MODE.NVIDIA && nvidiaLibrary.IsInstalled)
|
if (VideoMode == VIDEO_MODE.NVIDIA && nvidiaLibrary.IsInstalled)
|
||||||
{
|
{
|
||||||
nvidiaLibrary.UpdateActiveConfig();
|
nvidiaLibrary.UpdateActiveConfig();
|
||||||
winLibrary.UpdateActiveConfig();
|
winLibrary.UpdateActiveConfig(fastScan);
|
||||||
}
|
}
|
||||||
else if (VideoMode == VIDEO_MODE.AMD && amdLibrary.IsInstalled)
|
else if (VideoMode == VIDEO_MODE.AMD && amdLibrary.IsInstalled)
|
||||||
{
|
{
|
||||||
amdLibrary.UpdateActiveConfig();
|
amdLibrary.UpdateActiveConfig();
|
||||||
winLibrary.UpdateActiveConfig();
|
winLibrary.UpdateActiveConfig(fastScan);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
winLibrary.UpdateActiveConfig();
|
winLibrary.UpdateActiveConfig(fastScan);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the profile data from the current stored config (that we just updated)
|
// Grab the profile data from the current stored config (that we just updated)
|
||||||
|
@ -696,7 +696,7 @@ namespace DisplayMagicianShared
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UpdateActiveProfile()
|
public static void UpdateActiveProfile(bool fastScan = true)
|
||||||
{
|
{
|
||||||
|
|
||||||
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: Updating the profile currently active (in use now).");
|
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: Updating the profile currently active (in use now).");
|
||||||
@ -751,7 +751,7 @@ namespace DisplayMagicianShared
|
|||||||
//ShellHelper.TellShellToWriteSettings();
|
//ShellHelper.TellShellToWriteSettings();
|
||||||
//WinLibrary.RefreshTaskBars();
|
//WinLibrary.RefreshTaskBars();
|
||||||
|
|
||||||
profile.CreateProfileFromCurrentDisplaySettings();
|
profile.CreateProfileFromCurrentDisplaySettings(fastScan);
|
||||||
|
|
||||||
if (_profilesLoaded && _allProfiles.Count > 0)
|
if (_profilesLoaded && _allProfiles.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -473,12 +473,12 @@ namespace DisplayMagicianShared.Windows
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UpdateActiveConfig()
|
public bool UpdateActiveConfig(bool fastScan = true)
|
||||||
{
|
{
|
||||||
SharedLogger.logger.Trace($"WinLibrary/UpdateActiveConfig: Updating the currently active config");
|
SharedLogger.logger.Trace($"WinLibrary/UpdateActiveConfig: Updating the currently active config");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_activeDisplayConfig = GetActiveConfig();
|
_activeDisplayConfig = GetActiveConfig(fastScan);
|
||||||
_allConnectedDisplayIdentifiers = GetAllConnectedDisplayIdentifiers();
|
_allConnectedDisplayIdentifiers = GetAllConnectedDisplayIdentifiers();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -490,14 +490,14 @@ namespace DisplayMagicianShared.Windows
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WINDOWS_DISPLAY_CONFIG GetActiveConfig()
|
public WINDOWS_DISPLAY_CONFIG GetActiveConfig(bool fastScan = true)
|
||||||
{
|
{
|
||||||
SharedLogger.logger.Trace($"WinLibrary/GetActiveConfig: Getting the currently active config");
|
SharedLogger.logger.Trace($"WinLibrary/GetActiveConfig: Getting the currently active config");
|
||||||
// We'll leave virtual refresh rate aware until we can reliably detect Windows 11 versions.
|
// We'll leave virtual refresh rate aware until we can reliably detect Windows 11 versions.
|
||||||
return GetWindowsDisplayConfig(QDC.QDC_ONLY_ACTIVE_PATHS);
|
return GetWindowsDisplayConfig(QDC.QDC_ONLY_ACTIVE_PATHS, fastScan);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WINDOWS_DISPLAY_CONFIG GetWindowsDisplayConfig(QDC selector = QDC.QDC_ONLY_ACTIVE_PATHS)
|
private WINDOWS_DISPLAY_CONFIG GetWindowsDisplayConfig(QDC selector = QDC.QDC_ONLY_ACTIVE_PATHS, bool fastScan = true)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Prepare the empty windows display config
|
// Prepare the empty windows display config
|
||||||
@ -909,25 +909,32 @@ namespace DisplayMagicianShared.Windows
|
|||||||
// Check whether Windows has actually added the registry keys that outline the taskbar position
|
// Check whether Windows has actually added the registry keys that outline the taskbar position
|
||||||
if (retryNeeded)
|
if (retryNeeded)
|
||||||
{
|
{
|
||||||
// We wait until the reg key is populated
|
if (fastScan)
|
||||||
for (int count = 1; count <= 4; count++)
|
|
||||||
{
|
{
|
||||||
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: We were unable to get all the Windows Taskbar Layouts! So we need to try again. Attempt {count} of 4.");
|
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Skipping retrying Windows Taskbar Layouts and just accepting the first locations");
|
||||||
|
|
||||||
// Wait 5 seconds
|
|
||||||
System.Threading.Thread.Sleep(5000);
|
|
||||||
// then try again
|
|
||||||
retryNeeded = false;
|
|
||||||
taskBarStuckRectangles = TaskBarLayout.GetAllCurrentTaskBarLayouts(windowsDisplayConfig.DisplaySources, out retryNeeded);
|
|
||||||
|
|
||||||
if (!retryNeeded)
|
|
||||||
{
|
|
||||||
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: We successfully got the Windows Taskbar Layouts on attempt {count}! So we can stop trying to get them");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
// We wait until the reg key is populated
|
||||||
|
for (int count = 1; count <= 4; count++)
|
||||||
|
{
|
||||||
|
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: We were unable to get all the Windows Taskbar Layouts! So we need to try again. Attempt {count} of 4.");
|
||||||
|
|
||||||
|
// Wait 5 seconds
|
||||||
|
System.Threading.Thread.Sleep(5000);
|
||||||
|
// then try again
|
||||||
|
retryNeeded = false;
|
||||||
|
taskBarStuckRectangles = TaskBarLayout.GetAllCurrentTaskBarLayouts(windowsDisplayConfig.DisplaySources, out retryNeeded);
|
||||||
|
|
||||||
|
if (!retryNeeded)
|
||||||
|
{
|
||||||
|
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: We successfully got the Windows Taskbar Layouts on attempt {count}! So we can stop trying to get them");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now we try to get the taskbar settings too
|
// Now we try to get the taskbar settings too
|
||||||
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Attempting to get the Windows Taskbar Settings.");
|
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Attempting to get the Windows Taskbar Settings.");
|
||||||
|
Loading…
Reference in New Issue
Block a user