Skip to content

Commit

Permalink
Fixed auto resolution switching in some exotic cases
Browse files Browse the repository at this point in the history
  • Loading branch information
seerge committed Mar 14, 2023
1 parent bc965c0 commit 9bb5e41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
22 changes: 11 additions & 11 deletions NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using static Tools.ScreenInterrogatory;
using System.Windows.Forms;

namespace Tools
{
Expand Down Expand Up @@ -545,22 +546,19 @@ public static string FindLaptopScreen()

foreach (var device in devices)
{
if (device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL)
if (device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
device.outputTechnology == DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY.DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED)
{
displayNum = count;
}
count++;
//Debug.WriteLine(device.outputTechnology);
//Debug.WriteLine(device.monitorFriendlyDeviceName);
//Logger.WriteLine(device.outputTechnology.ToString());
//Logger.WriteLine(device.monitorFriendlyDeviceName);
}

var screens = Screen.AllScreens;

if (screens.Length != count)
{
Debug.WriteLine("Mismatch between enumerated and available screens");
return null;
}
if (screens.Length != count) return null;

count = 0;
foreach (var screen in screens)
Expand All @@ -569,13 +567,15 @@ public static string FindLaptopScreen()
{
laptopScreen = screen.DeviceName;
}
//Debug.WriteLine(screen.DeviceName);
//Logger.WriteLine(screen.DeviceName);
count++;
}
}
catch
catch (Exception ex)
{
Debug.WriteLine("Can't find internal screen");
Logger.WriteLine(ex.ToString());
Logger.WriteLine("Can't detect internal screen");
//laptopScreen = Screen.PrimaryScreen.DeviceName;
}


Expand Down
18 changes: 13 additions & 5 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ public static void WriteLine(string logMessage)
Debug.WriteLine(logMessage);
if (!Directory.Exists(appPath)) Directory.CreateDirectory(appPath);

using (StreamWriter w = File.AppendText(logFile))
try
{
w.WriteLine($"{DateTime.Now}: {logMessage}");
using (StreamWriter w = File.AppendText(logFile))
{
w.WriteLine($"{DateTime.Now}: {logMessage}");
w.Close();
}
} catch
{

}

var rand = new Random();
if (rand.Next(50) == 1) Cleanup();
if (new Random().Next(100) == 1) Cleanup();


}
Expand Down Expand Up @@ -214,7 +220,9 @@ public static void SetAutoModes()
settingsForm.SetBatteryChargeLimit(config.getConfig("charge_limit"));

settingsForm.AutoPerformance(isPlugged);
settingsForm.AutoGPUMode(isPlugged);

bool switched = settingsForm.AutoGPUMode(isPlugged);
if (!switched) settingsForm.AutoScreen(isPlugged);

settingsForm.SetMatrix(isPlugged);
}
Expand Down
14 changes: 7 additions & 7 deletions Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -858,33 +858,33 @@ public void AutoScreen(PowerLineStatus Plugged = PowerLineStatus.Online)

}

public void AutoGPUMode(PowerLineStatus Plugged = PowerLineStatus.Online)
public bool AutoGPUMode(PowerLineStatus Plugged = PowerLineStatus.Online)
{

int GpuAuto = Program.config.getConfig("gpu_auto");
if (GpuAuto != 1) return;
if (GpuAuto != 1) return false;

int eco = Program.wmi.DeviceGet(ASUSWmi.GPUEco);
int mux = Program.wmi.DeviceGet(ASUSWmi.GPUMux);

if (mux == 0) // GPU in Ultimate, ignore
return;
return false;
else
{
if (eco == 1 && Plugged == PowerLineStatus.Online) // Eco going Standard on plugged
{
SetEcoGPU(0);
return true;
}
else if (eco == 0 && Plugged != PowerLineStatus.Online) // Standard going Eco on plugged
{
SetEcoGPU(1);
}
else
{
AutoScreen(Plugged);
return true;
}
}

return false;

}

public int InitGPUMode()
Expand Down

0 comments on commit 9bb5e41

Please sign in to comment.