Skip to content

Commit d5889d4

Browse files
committed
Implement a whitelist/enabledApps
1 parent 78149f8 commit d5889d4

File tree

1 file changed

+68
-21
lines changed

1 file changed

+68
-21
lines changed

src/main.cpp

Lines changed: 68 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace ImGui
5454
using namespace std::chrono_literals;
5555
using namespace vr;
5656

57-
static constexpr const char *version = "v1.1.0";
57+
static constexpr const char *version = "v1.2.0";
5858

5959
static constexpr const char *iconPath = "icon.png";
6060

@@ -78,12 +78,15 @@ int minimizeOnStart = 0;
7878
// General
7979
int resChangeDelayMs = 3000;
8080
int dataAverageSamples = 128;
81-
std::string disabledApps = "steam.app.620980 steam.app.658920 steam.app.2177750 steam.app.2177760"; // Beat Saber and HL2VR
82-
std::set<std::string> disabledAppsSet = {"steam.app.620980", "steam.app.658920", "steam.app.2177750", "steam.app.2177760"};
81+
std::string blacklistApps = "steam.app.620980 steam.app.658920 steam.app.2177750 steam.app.2177760"; // Beat Saber and HL2VR
82+
std::set<std::string> blacklistAppsSet = {"steam.app.620980", "steam.app.658920", "steam.app.2177750", "steam.app.2177760"};
83+
bool whitelistEnabled = false;
84+
std::string whitelistApps = "";
85+
std::set<std::string> whitelistAppsSet = {};
8386
// Resolution
8487
int initialRes = 100;
8588
int minRes = 70;
86-
int maxRes = 250;
89+
int maxRes = 200;
8790
int resIncreaseThreshold = 80;
8891
int resDecreaseThreshold = 88;
8992
int resIncreaseMin = 3;
@@ -147,14 +150,22 @@ bool loadSettings()
147150
// Startup
148151
autoStart = std::stoi(ini.GetValue("Startup", "autoStart", std::to_string(autoStart).c_str()));
149152
minimizeOnStart = std::stoi(ini.GetValue("Startup", "minimizeOnStart", std::to_string(minimizeOnStart).c_str()));
153+
150154
// General
151155
resChangeDelayMs = std::stoi(ini.GetValue("General", "resChangeDelayMs", std::to_string(resChangeDelayMs).c_str()));
152156
dataAverageSamples = std::stoi(ini.GetValue("General", "dataAverageSamples", std::to_string(dataAverageSamples).c_str()));
153157
if (dataAverageSamples > 128)
154158
dataAverageSamples = 128; // Max stored by OpenVR
155-
disabledApps = ini.GetValue("General", "disabledApps", disabledApps.c_str());
156-
std::replace(disabledApps.begin(), disabledApps.end(), ' ', '\n');
157-
disabledAppsSet = multilineStringToSet(disabledApps);
159+
// blacklist
160+
blacklistApps = ini.GetValue("General", "disabledApps", blacklistApps.c_str());
161+
std::replace(blacklistApps.begin(), blacklistApps.end(), ' ', '\n');
162+
blacklistAppsSet = multilineStringToSet(blacklistApps);
163+
// whitelist
164+
whitelistEnabled = std::stoi(ini.GetValue("General", "whitelistEnabled", std::to_string(whitelistEnabled).c_str()));
165+
whitelistApps = ini.GetValue("General", "whitelistApps", blacklistApps.c_str());
166+
std::replace(whitelistApps.begin(), whitelistApps.end(), ' ', '\n');
167+
whitelistAppsSet = multilineStringToSet(whitelistApps);
168+
158169
// Resolution
159170
initialRes = std::stoi(ini.GetValue("Resolution", "initialRes", std::to_string(initialRes).c_str()));
160171
minRes = std::stoi(ini.GetValue("Resolution", "minRes", std::to_string(minRes).c_str()));
@@ -167,15 +178,18 @@ bool loadSettings()
167178
resDecreaseScale = std::stoi(ini.GetValue("Resolution", "resDecreaseScale", std::to_string(resDecreaseScale).c_str()));
168179
minCpuTimeThreshold = std::stof(ini.GetValue("Resolution", "minCpuTimeThreshold", std::to_string(minCpuTimeThreshold).c_str()));
169180
resetOnThreshold = std::stoi(ini.GetValue("Resolution", "resetOnThreshold", std::to_string(resetOnThreshold).c_str()));
181+
170182
// Reprojection
171183
alwaysReproject = std::stoi(ini.GetValue("Reprojection", "alwaysReproject", std::to_string(alwaysReproject).c_str()));
172184
preferReprojection = std::stoi(ini.GetValue("Reprojection", "preferReprojection", std::to_string(preferReprojection).c_str()));
173185
ignoreCpuTime = std::stoi(ini.GetValue("Reprojection", "ignoreCpuTime", std::to_string(ignoreCpuTime).c_str()));
186+
174187
// VRAM
175188
vramMonitorEnabled = std::stoi(ini.GetValue("VRAM", "vramMonitorEnabled", std::to_string(vramMonitorEnabled).c_str()));
176189
vramOnlyMode = std::stoi(ini.GetValue("VRAM", "vramOnlyMode", std::to_string(vramOnlyMode).c_str()));
177190
vramTarget = std::stoi(ini.GetValue("VRAM", "vramTarget", std::to_string(vramTarget).c_str()));
178191
vramLimit = std::stoi(ini.GetValue("VRAM", "vramLimit", std::to_string(vramLimit).c_str()));
192+
179193
return true;
180194
}
181195
catch (...)
@@ -192,10 +206,14 @@ void saveSettings()
192206
// Startup
193207
ini.SetValue("Startup", "autoStart", std::to_string(autoStart).c_str());
194208
ini.SetValue("Startup", "minimizeOnStart", std::to_string(minimizeOnStart).c_str());
209+
195210
// General
196211
ini.SetValue("General", "resChangeDelayMs", std::to_string(resChangeDelayMs).c_str());
197212
ini.SetValue("General", "dataAverageSamples", std::to_string(dataAverageSamples).c_str());
198-
ini.SetValue("General", "disabledApps", setToConfigString(disabledAppsSet).c_str());
213+
ini.SetValue("General", "disabledApps", setToConfigString(blacklistAppsSet).c_str());
214+
ini.SetValue("General", "whitelistEnabled", std::to_string(whitelistEnabled).c_str());
215+
ini.SetValue("General", "whitelistApps", setToConfigString(whitelistAppsSet).c_str());
216+
199217
// Resolution
200218
ini.SetValue("Resolution", "initialRes", std::to_string(initialRes).c_str());
201219
ini.SetValue("Resolution", "minRes", std::to_string(minRes).c_str());
@@ -208,10 +226,12 @@ void saveSettings()
208226
ini.SetValue("Resolution", "resDecreaseScale", std::to_string(resDecreaseScale).c_str());
209227
ini.SetValue("Resolution", "minCpuTimeThreshold", std::to_string(minCpuTimeThreshold).c_str());
210228
ini.SetValue("Resolution", "resetOnThreshold", std::to_string(resetOnThreshold).c_str());
229+
211230
// Reprojection
212231
ini.SetValue("Reprojection", "alwaysReproject", std::to_string(alwaysReproject).c_str());
213232
ini.SetValue("Reprojection", "preferReprojection", std::to_string(preferReprojection).c_str());
214233
ini.SetValue("Reprojection", "ignoreCpuTime", std::to_string(ignoreCpuTime).c_str());
234+
215235
// VRAM
216236
ini.SetValue("VRAM", "vramMonitorEnabled", std::to_string(vramMonitorEnabled).c_str());
217237
ini.SetValue("VRAM", "vramOnlyMode", std::to_string(vramOnlyMode).c_str());
@@ -302,19 +322,24 @@ std::string getCurrentApplicationKey()
302322
return {applicationKey};
303323
}
304324

305-
bool isApplicationDisabled(std::string appKey)
325+
bool isApplicationBlacklisted(std::string appKey)
306326
{
307-
return disabledAppsSet.find(appKey) != disabledAppsSet.end() || appKey == "";
327+
return appKey == "" || blacklistAppsSet.find(appKey) != blacklistAppsSet.end();
328+
}
329+
330+
bool isApplicationWhitelisted(std::string appKey)
331+
{
332+
return appKey != "" && whitelistAppsSet.find(appKey) != whitelistAppsSet.end();
308333
}
309334

310335
bool shouldAdjustResolution(std::string appKey, bool manualRes, float cpuTime)
311336
{
312337
// Check if the SteamVR dashboard is open
313338
bool inDashboard = vr::VROverlay()->IsDashboardVisible();
314339
// Check that we're in a supported application
315-
bool isCurrentAppDisabled = isApplicationDisabled(appKey);
340+
bool isCurrentAppSupported = !isApplicationBlacklisted(appKey) && (!whitelistEnabled || isApplicationWhitelisted(appKey));
316341
// Only adjust resolution if not in dashboard, in a supported application. user didn't pause res and cpu time isn't below threshold
317-
return !inDashboard && !isCurrentAppDisabled && !manualRes && !(resetOnThreshold && cpuTime < minCpuTimeThreshold);
342+
return !inDashboard && isCurrentAppSupported && !manualRes && !(resetOnThreshold && cpuTime < minCpuTimeThreshold);
318343
}
319344

320345
void printLine(std::string text, long duration)
@@ -472,8 +497,10 @@ int main(int argc, char *argv[])
472497
#pragma endregion
473498

474499
// Load settings from ini file
475-
if (!loadSettings())
500+
if (!loadSettings()) {
501+
std::replace(blacklistApps.begin(), blacklistApps.end(), ' ', '\n'); // Set blacklist newlines
476502
saveSettings(); // Restore settings
503+
}
477504

478505
// Set auto-start
479506
int autoStartResult = handle_setup(autoStart);
@@ -927,19 +954,39 @@ int main(int argc, char *argv[])
927954
}
928955
addTooltip("Number of frames' frametimes to average out.");
929956

930-
if (ImGui::InputTextMultiline("Disabled applications", &disabledApps, ImVec2(130, 60)))
931-
disabledAppsSet = multilineStringToSet(disabledApps);
932-
addTooltip("List of OpenVR application keys that should be ignored for resolution adjustment in the format \'steam.app.APPID\' (e.g. steam.app.620980 for Beat Saber). One per line.");
933-
if (ImGui::Button("Disable current application", ImVec2(200, 26)))
957+
ImGui::Text("Blacklist");
958+
addTooltip("Don't allow resolution changes in blacklisted applications.");
959+
if (ImGui::InputTextMultiline("Blacklisted apps", &blacklistApps, ImVec2(130, 60), ImGuiInputTextFlags_CharsNoBlank))
960+
blacklistAppsSet = multilineStringToSet(blacklistApps);
961+
addTooltip("List of OpenVR application keys that should be blacklisted for resolution adjustment in the format \'steam.app.APPID\' (e.g. \'steam.app.620980\' for Beat Saber). One per line.");
962+
if (ImGui::Button("Blacklist current app", ImVec2(160, 26)))
963+
{
964+
std::string appKey = getCurrentApplicationKey();
965+
if (!isApplicationBlacklisted(appKey))
966+
{
967+
blacklistAppsSet.insert(appKey);
968+
if (blacklistApps != "") blacklistApps += "\n";
969+
blacklistApps += appKey;
970+
}
971+
}
972+
addTooltip("Adds the current application to the blacklist.");
973+
974+
ImGui::Checkbox("Enable whitelist", &whitelistEnabled);
975+
addTooltip("Only allow resolution changes in whitelisted applications.");
976+
if (ImGui::InputTextMultiline("Whitelisted apps", &whitelistApps, ImVec2(130, 60), ImGuiInputTextFlags_CharsNoBlank))
977+
whitelistAppsSet = multilineStringToSet(whitelistApps);
978+
addTooltip("List of OpenVR application keys that should be whitelisted for resolution adjustment in the format \'steam.app.APPID\' (e.g. \'steam.app.620980\' for Beat Saber). One per line.");
979+
if (ImGui::Button("Whitelist current app", ImVec2(164, 26)))
934980
{
935981
std::string appKey = getCurrentApplicationKey();
936-
if (!isApplicationDisabled(appKey))
982+
if (!isApplicationWhitelisted(appKey))
937983
{
938-
disabledAppsSet.insert(appKey);
939-
disabledApps += "\n" + appKey;
984+
whitelistAppsSet.insert(appKey);
985+
if (whitelistApps != "") whitelistApps += "\n";
986+
whitelistApps += appKey;
940987
}
941988
}
942-
addTooltip("Adds the current application to the list of disable applications.");
989+
addTooltip("Adds the current application to the whitelist.");
943990
}
944991

945992
if (ImGui::CollapsingHeader("Resolution"))

0 commit comments

Comments
 (0)