Skip to content

Commit

Permalink
added hdr toggle action
Browse files Browse the repository at this point in the history
  • Loading branch information
Odizinne committed Nov 11, 2024
1 parent 2fdc475 commit 5a64dce
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 28 deletions.
4 changes: 4 additions & 0 deletions BigPictureTV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17 silent lrelease embed_translations

QM_FILES_RESOURCE_PREFIX = /translations
DEPS_DIR = $$PWD/Dependencies
BUILD_DIR = $$OUT_PWD

INCLUDEPATH += \
AudioManager \
Expand Down Expand Up @@ -48,3 +50,5 @@ RESOURCES += \
RC_FILE = Resources/appicon.rc

LIBS += -lole32 -luser32 -ladvapi32 -lshell32

QMAKE_POST_LINK = powershell -Command "Copy-Item -Path '$$DEPS_DIR' -Recurse -Destination '$$BUILD_DIR/release'"
15 changes: 15 additions & 0 deletions BigPictureTV/BigPictureTV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void BigPictureTV::checkWindowTitle()
gamemodeActive = true;
handleActions(false);
handleMonitorChanges(false, disable_monitor_switch);
checkAndSetHDR(false);
if (skip_intro) {
Utils::skipBigPictureIntro();
}
Expand All @@ -91,6 +92,7 @@ void BigPictureTV::checkWindowTitle()
} else if (!isRunning && gamemodeActive) {
gamemodeActive = false;
handleActions(true);
checkAndSetHDR(true);
handleMonitorChanges(true, disable_monitor_switch);
handleAudioChanges(true, disable_audio_switch);
settings.setValue("gamemode", gamemodeActive);
Expand Down Expand Up @@ -118,6 +120,18 @@ void BigPictureTV::handleMonitorChanges(bool isDesktopMode, bool disableVideo)
}
}

void BigPictureTV::checkAndSetHDR(bool isDesktopMode)
{
if (!enable_hdr) {
return;
}

QString command = isDesktopMode ? "off" : "on";
if (Utils::getHDRStatus() != 2) {
Utils::setHDR(command);
}
}

void BigPictureTV::handleAudioChanges(bool isDesktopMode, bool disableAudio)
{
if (disableAudio) {
Expand Down Expand Up @@ -207,6 +221,7 @@ void BigPictureTV::loadSettings()
target_window_mode = settings.value("target_window_mode").toInt();
custom_window_title = settings.value("custom_window_title").toString();
skip_intro = settings.value("skip_intro").toBool();
enable_hdr = settings.value("enable_hdr").toBool();
}

void BigPictureTV::showSettings()
Expand Down
2 changes: 2 additions & 0 deletions BigPictureTV/BigPictureTV.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private slots:
void showSettings();
void startupReset();
void changeDetectionState();
void checkAndSetHDR(bool isDesktopMode);

QString gamemode_audio_device;
QString desktop_audio_device;
Expand All @@ -59,6 +60,7 @@ private slots:
bool disable_nightlight_action;
int target_window_mode;
bool skip_intro;
bool enable_hdr;
QSettings settings;
bool gamemodeActive;
};
Expand Down
11 changes: 11 additions & 0 deletions Configurator/Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Configurator::Configurator(QWidget *parent)
this->setWindowIcon(Utils::getIconForTheme());
populateComboboxes();
populateAudioComboBoxes();
getHDRCapabilities();
loadSettings();
ui->avFrame->setVisible(false);
ui->actionsFrame->setVisible(false);
Expand Down Expand Up @@ -134,6 +135,7 @@ void Configurator::loadSettings()
ui->customWindowLineEdit->setText(settings.value("custom_window_title", "").toString());
ui->targetWindowComboBox->setCurrentIndex(settings.value("target_window_mode", 0).toInt());
ui->skipIntroCheckBox->setChecked(settings.value("skip_intro", false).toBool());
ui->HDRCheckBox->setChecked(settings.value("enable_hdr", false).toBool());

toggleAudioSettings(!ui->disableAudioCheckBox->isChecked());
toggleMonitorSettings(!ui->disableMonitorCheckBox->isChecked());
Expand Down Expand Up @@ -161,6 +163,7 @@ void Configurator::saveSettings()
settings.setValue("target_window_mode", ui->targetWindowComboBox->currentIndex());
settings.setValue("custom_window_title", ui->customWindowLineEdit->text());
settings.setValue("skip_intro", ui->skipIntroCheckBox->isChecked());
settings.setValue("enable_hdr", ui->HDRCheckBox->isChecked());
}

void Configurator::toggleAudioSettings(bool state)
Expand Down Expand Up @@ -300,3 +303,11 @@ void Configurator::selectAudioDeviceFromSettings(QComboBox *comboBox, const QStr
comboBox->setCurrentIndex(index);
}
}

void Configurator::getHDRCapabilities()
{
if (Utils::getHDRStatus() == 2) {
ui->HDRLabel->setDisabled(true);
ui->HDRCheckBox->setDisabled(true);
}
}
1 change: 1 addition & 0 deletions Configurator/Configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private slots:
void createDefaultSettings();
void loadSettings();
void saveSettings();
void getHDRCapabilities();
void fadeIn(QWidget *widget);
void fadeOut(QWidget *widget, std::function<void()> onFinished);
void switchTab(int targetFrame, QPushButton* targetButton, QWidget* targetFrameWidget);
Expand Down
85 changes: 57 additions & 28 deletions Configurator/Configurator.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>379</width>
<height>704</height>
<height>712</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -84,28 +84,41 @@
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="disableNightLightLabel">
<item row="3" column="0">
<widget class="QLabel" name="gamemodePowerPlanLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Will revert to previous night light state</string>
<string>Will revert to previously set power plan</string>
</property>
<property name="text">
<string>Disable night light</string>
<string>Enable performance power plan</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="pauseMediaAction">
<item row="4" column="0">
<widget class="QLabel" name="pauseMediaLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
<height>0</height>
</size>
</property>
<property name="text">
<string>Pause currently playing media</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="disableNightLightCheckBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
Expand All @@ -116,41 +129,44 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="gamemodePowerPlanLabel">
<item row="4" column="1">
<widget class="QCheckBox" name="pauseMediaAction">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Will revert to previously set power plan</string>
<property name="layoutDirection">
<enum>Qt::LayoutDirection::RightToLeft</enum>
</property>
<property name="text">
<string>Enable performance power plan</string>
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<item row="2" column="0">
<widget class="QLabel" name="disableNightLightLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Will revert to previous night light state</string>
</property>
<property name="text">
<string>Pause currently playing media</string>
<string>Disable night light</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QCheckBox" name="enablePerformancePowerPlan">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
Expand All @@ -161,12 +177,12 @@
</property>
</widget>
</item>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="CloseDiscordLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>25</height>
<height>0</height>
</size>
</property>
<property name="toolTip">
Expand All @@ -178,11 +194,11 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="disableNightLightCheckBox">
<widget class="QCheckBox" name="closeDiscordCheckBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
Expand All @@ -193,12 +209,25 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="HDRLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Enable HDR</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="closeDiscordCheckBox">
<widget class="QCheckBox" name="HDRCheckBox">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
<height>0</height>
</size>
</property>
<property name="layoutDirection">
Expand Down Expand Up @@ -486,7 +515,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="skipIntroLabel">
<property name="minimumSize">
<size>
<width>0</width>
Expand Down
Binary file added Dependencies/HDRCmd.exe
Binary file not shown.
31 changes: 31 additions & 0 deletions Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,34 @@ bool Utils::isWindows10()
int buildNumber = getBuildNumber();
return (buildNumber >= 10240 && buildNumber < 22000);
}

int Utils::getHDRStatus()
{
QString program = QCoreApplication::applicationDirPath() + "/Dependencies/HDRCmd.exe";
QStringList arguments;
arguments << "status" << "-m" << "exitcode";
QProcess process;
process.start(program, arguments);

if (!process.waitForFinished()) {
qDebug() << "Process failed to finish";
return -1;
}

int exitCode = process.exitCode();
return exitCode;
}

void Utils::setHDR(QString mode)
{
QString program = QCoreApplication::applicationDirPath() + "/Dependencies/HDRCmd.exe";
QStringList arguments;
arguments << mode;
QProcess process;
process.start(program, arguments);

if (!process.waitForFinished()) {
qDebug() << "Process failed to finish";
return;
}
}
2 changes: 2 additions & 0 deletions Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace Utils {
void sendMediaKey(WORD keyCode);
void skipBigPictureIntro();
bool isWindows10();
int getHDRStatus();
void setHDR(QString mode);
}

#endif // UTILS_H

0 comments on commit 5a64dce

Please sign in to comment.