Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to set a custom window resolution #463

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
10 changes: 10 additions & 0 deletions gui/include/qmlsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class QmlSettings : public QObject
Q_PROPERTY(QString audioOutDevice READ audioOutDevice WRITE setAudioOutDevice NOTIFY audioOutDeviceChanged)
Q_PROPERTY(QString decoder READ decoder WRITE setDecoder NOTIFY decoderChanged)
Q_PROPERTY(int windowType READ windowType WRITE setWindowType NOTIFY windowTypeChanged)
Q_PROPERTY(uint customResolutionWidth READ customResolutionWidth WRITE setCustomResolutionWidth NOTIFY customResolutionWidthChanged)
Q_PROPERTY(uint customResolutionHeight READ customResolutionHeight WRITE setCustomResolutionHeight NOTIFY customResolutionHeightChanged)
Q_PROPERTY(int videoPreset READ videoPreset WRITE setVideoPreset NOTIFY videoPresetChanged)
Q_PROPERTY(float sZoomFactor READ sZoomFactor WRITE setSZoomFactor NOTIFY sZoomFactorChanged)
Q_PROPERTY(int packetLossMax READ packetLossMax WRITE setPacketLossMax NOTIFY packetLossMaxChanged)
Expand Down Expand Up @@ -215,6 +217,12 @@ class QmlSettings : public QObject
int windowType() const;
void setWindowType(int type);

uint customResolutionWidth() const;
void setCustomResolutionWidth(uint width);

uint customResolutionHeight() const;
void setCustomResolutionHeight(uint length);

float sZoomFactor() const;
void setSZoomFactor(float factor);

Expand Down Expand Up @@ -497,6 +505,8 @@ class QmlSettings : public QObject
void wifiDroppedNotifChanged();
void decoderChanged();
void windowTypeChanged();
void customResolutionWidthChanged();
void customResolutionHeightChanged();
void sZoomFactorChanged();
void videoPresetChanged();
void autoConnectMacChanged();
Expand Down
7 changes: 7 additions & 0 deletions gui/include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ enum class PlaceboPreset {

enum class WindowType {
SelectedResolution,
CustomResolution,
Fullscreen,
Zoom,
Stretch
Expand Down Expand Up @@ -291,6 +292,12 @@ class Settings : public QObject
WindowType GetWindowType() const;
void SetWindowType(WindowType type);

uint GetCustomResolutionWidth() const;
void SetCustomResolutionWidth(uint width);

uint GetCustomResolutionHeight() const;
void SetCustomResolutionHeight(uint length);

PlaceboPreset GetPlaceboPreset() const;
void SetPlaceboPreset(PlaceboPreset preset);

Expand Down
68 changes: 66 additions & 2 deletions gui/src/qml/SettingsDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,78 @@ DialogView {

C.ComboBox {
Layout.preferredWidth: 400
model: [qsTr("Selected Resolution"), qsTr("Fullscreen"), qsTr("Zoom [adjust zoom using slider in stream menu]"), qsTr("Stretch")]
model: [qsTr("Stream Resolution"), qsTr("Custom Resolution"), qsTr("Fullscreen"), qsTr("Zoom [adjust zoom using slider in stream menu]"), qsTr("Stretch")]
currentIndex: Chiaki.settings.windowType
onActivated: (index) => Chiaki.settings.windowType = index;
}

Label {
Layout.alignment: Qt.AlignRight
text: qsTr("(Selected Resolution)")
text: qsTr("(Stream Resolution)")
}

Label {
Layout.alignment: Qt.AlignRight
text: qsTr("Custom Resolution Width")
visible: Chiaki.settings.windowType == 1
}

C.TextField {
id: customResolutionWidth
Layout.preferredWidth: 400
visible: Chiaki.settings.windowType == 1
text: Chiaki.settings.customResolutionWidth
Material.accent: text && !validate() ? Material.Red : undefined
onEditingFinished: {
if (validate()) {
Chiaki.settings.customResolutionWidth = parseInt(text);
} else {
Chiaki.settings.customResolutionWidth = 0;
text = "";
}
}
function validate() {
var num = parseInt(text);
return num >= 0 && num <= 9999;
}
}

Label {
Layout.alignment: Qt.AlignRight
text: qsTr("(1920)")
visible: Chiaki.settings.windowType == 1
}

Label {
Layout.alignment: Qt.AlignRight
text: qsTr("Custom Resolution Height")
visible: Chiaki.settings.windowType == 1
}

C.TextField {
id: customResolutionHeight
Layout.preferredWidth: 400
visible: Chiaki.settings.windowType == 1
text: Chiaki.settings.customResolutionHeight
Material.accent: text && !validate() ? Material.Red : undefined
onEditingFinished: {
if (validate()) {
Chiaki.settings.customResolutionHeight = parseInt(text);
} else {
Chiaki.settings.customResolutionHeight = 0;
text = "";
}
}
function validate() {
var num = parseInt(text);
return num >= 0 && num <= 9999;
}
}

Label {
Layout.alignment: Qt.AlignRight
text: qsTr("(1080)")
visible: Chiaki.settings.windowType == 1
}

Label {
Expand Down
12 changes: 11 additions & 1 deletion gui/src/qmlbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,15 @@ void QmlBackend::createSession(const StreamSessionConnectInfo &connect_info)
});

if (window->windowState() != Qt::WindowFullScreen)
window->resize(connect_info.video_profile.width, connect_info.video_profile.height);
{
if(settings->GetWindowType() == WindowType::CustomResolution)
{
window->resize(settings->GetCustomResolutionWidth(), settings->GetCustomResolutionHeight());
window->setMaximumSize(QSize(settings->GetCustomResolutionWidth(), settings->GetCustomResolutionHeight()));
}
else
window->resize(connect_info.video_profile.width, connect_info.video_profile.height);
}

chiaki_log_mutex.lock();
chiaki_log_ctx = session->GetChiakiLog();
Expand Down Expand Up @@ -1016,6 +1024,8 @@ void QmlBackend::connectToHost(int index, QString nickname)
switch (settings->GetWindowType()) {
case WindowType::SelectedResolution:
break;
case WindowType::CustomResolution:
break;
case WindowType::Fullscreen:
fullscreen = true;
break;
Expand Down
5 changes: 3 additions & 2 deletions gui/src/qmlmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ void QmlMainWindow::updateWindowType(WindowType type)
switch (type) {
case WindowType::SelectedResolution:
break;
case WindowType::CustomResolution:
break;
case WindowType::Fullscreen:
showFullScreen();
break;
Expand Down Expand Up @@ -270,8 +272,7 @@ void QmlMainWindow::show()
QMetaObject::invokeMethod(QGuiApplication::instance(), &QGuiApplication::quit, Qt::QueuedConnection);
return;
}

resize(1280, 720);
resize(1920, 1080);

if (qEnvironmentVariable("XDG_CURRENT_DESKTOP") == "gamescope")
showFullScreen();
Expand Down
24 changes: 24 additions & 0 deletions gui/src/qmlsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,28 @@ void QmlSettings::setWindowType(int type)
emit windowTypeChanged();
}

uint QmlSettings::customResolutionWidth() const
{
return settings->GetCustomResolutionWidth();
}

void QmlSettings::setCustomResolutionWidth(uint width)
{
settings->SetCustomResolutionWidth(width);
emit customResolutionWidthChanged();
}

uint QmlSettings::customResolutionHeight() const
{
return settings->GetCustomResolutionHeight();
}

void QmlSettings::setCustomResolutionHeight(uint length)
{
settings->SetCustomResolutionHeight(length);
emit customResolutionHeightChanged();
}

float QmlSettings::sZoomFactor() const
{
return settings->GetZoomFactor();
Expand Down Expand Up @@ -1303,6 +1325,8 @@ void QmlSettings::refreshAllKeys()
emit wifiDroppedNotifChanged();
emit decoderChanged();
emit windowTypeChanged();
emit customResolutionWidthChanged();
emit customResolutionHeightChanged();
emit sZoomFactorChanged();
emit videoPresetChanged();
emit autoConnectMacChanged();
Expand Down
21 changes: 21 additions & 0 deletions gui/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ void Settings::SetPacketLossMax(float packet_loss_max)

static const QMap<WindowType, QString> window_type_values = {
{ WindowType::SelectedResolution, "Selected Resolution" },
{ WindowType::CustomResolution, "Custom Resolution"},
{ WindowType::Fullscreen, "Fullscreen" },
{ WindowType::Zoom, "Zoom" },
{ WindowType::Stretch, "Stretch" }
Expand All @@ -621,6 +622,26 @@ void Settings::SetWindowType(WindowType type)
settings.setValue("settings/window_type", window_type_values[type]);
}

uint Settings::GetCustomResolutionWidth() const
{
return settings.value("settings/custom_resolution_width", 1920).toUInt();
}

void Settings::SetCustomResolutionWidth(uint width)
{
settings.setValue("settings/custom_resolution_width", width);
}

uint Settings::GetCustomResolutionHeight() const
{
return settings.value("settings/custom_resolution_length", 1080).toUInt();
}

void Settings::SetCustomResolutionHeight(uint length)
{
settings.setValue("settings/custom_resolution_length", length);
}

RegisteredHost Settings::GetAutoConnectHost() const
{
const QByteArray mac = settings.value("settings/auto_connect_mac").toByteArray();
Expand Down
Loading