Skip to content

Commit

Permalink
Add --exit-app-on-stream-exit command line option
Browse files Browse the repository at this point in the history
Notable Changes:
- users can use --exit-app-on-stream-exit to make the GUI close as soon as the streamsession closes
Closes #443
  • Loading branch information
streetpea committed Oct 19, 2024
1 parent 7486f2a commit 88c9f9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gui/include/qmlmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class QmlMainWindow : public QWindow
};
Q_ENUM(VideoPreset);

QmlMainWindow(Settings *settings);
QmlMainWindow(Settings *settings, bool exit_app_on_stream_exit = false);
QmlMainWindow(const StreamSessionConnectInfo &connect_info);
~QmlMainWindow();
void updateWindowType(WindowType type);
Expand Down Expand Up @@ -101,7 +101,7 @@ class QmlMainWindow : public QWindow
void menuRequested();

private:
void init(Settings *settings);
void init(Settings *settings, bool exit_app_on_stream_exit = false);
void update();
void scheduleUpdate();
void createSwapchain();
Expand Down
13 changes: 9 additions & 4 deletions gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static const QMap<QString, CLICommand> cli_commands = {
#endif

int RunStream(QGuiApplication &app, const StreamSessionConnectInfo &connect_info);
int RunMain(QGuiApplication &app, Settings *settings);
int RunMain(QGuiApplication &app, Settings *settings, bool exit_app_on_stream_exit);

int real_main(int argc, char *argv[])
{
Expand Down Expand Up @@ -126,6 +126,9 @@ int real_main(int argc, char *argv[])
QCommandLineOption profile_option("profile", "", "profile", "Configuration profile");
parser.addOption(profile_option);

QCommandLineOption stream_exit_option("exit-app-on-stream-exit", "Exit the GUI application when the stream session ends.");
parser.addOption(stream_exit_option);

QCommandLineOption regist_key_option("registkey", "", "registkey");
parser.addOption(regist_key_option);

Expand All @@ -151,6 +154,7 @@ int real_main(int argc, char *argv[])
QStringList args = parser.positionalArguments();

Settings settings(parser.isSet(profile_option) ? parser.value(profile_option) : QString());
bool exit_app_on_stream_exit = parser.isSet(stream_exit_option);
if(parser.isSet(profile_option))
settings.SetCurrentProfile(parser.value(profile_option));
Settings alt_settings(parser.isSet(profile_option) ? "" : settings.GetCurrentProfile());
Expand All @@ -161,7 +165,7 @@ int real_main(int argc, char *argv[])
use_alt_settings = true;

if(args.length() == 0)
return RunMain(app, use_alt_settings ? &alt_settings : &settings);
return RunMain(app, use_alt_settings ? &alt_settings : &settings, exit_app_on_stream_exit);

if(args[0] == "list")
{
Expand Down Expand Up @@ -286,9 +290,10 @@ int real_main(int argc, char *argv[])
}
}

int RunMain(QGuiApplication &app, Settings *settings)
int RunMain(QGuiApplication &app, Settings *settings, bool exit_app_on_stream_exit)
{
QmlMainWindow main_window(settings);
printf("Exit app on stream exit %d\n", exit_app_on_stream_exit);
QmlMainWindow main_window(settings, exit_app_on_stream_exit);
main_window.show();
return app.exec();
}
Expand Down
15 changes: 11 additions & 4 deletions gui/src/qmlmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class RenderControl : public QQuickRenderControl
QWindow *window = {};
};

QmlMainWindow::QmlMainWindow(Settings *settings)
QmlMainWindow::QmlMainWindow(Settings *settings, bool exit_app_on_stream_exit)
: QWindow()
, settings(settings)
{
init(settings);
init(settings, exit_app_on_stream_exit);
}

QmlMainWindow::QmlMainWindow(const StreamSessionConnectInfo &connect_info)
Expand Down Expand Up @@ -345,7 +345,7 @@ AVBufferRef *QmlMainWindow::vulkanHwDeviceCtx()
return vulkan_hw_dev_ctx;
}

void QmlMainWindow::init(Settings *settings)
void QmlMainWindow::init(Settings *settings, bool exit_app_on_stream_exit)
{
setSurfaceType(QWindow::VulkanSurface);

Expand Down Expand Up @@ -489,14 +489,21 @@ void QmlMainWindow::init(Settings *settings)
connect(qml_engine, &QQmlEngine::quit, this, &QWindow::close);

backend = new QmlBackend(settings, this);
connect(backend, &QmlBackend::sessionChanged, this, [this](StreamSession *s) {
connect(backend, &QmlBackend::sessionChanged, this, [this, exit_app_on_stream_exit](StreamSession *s) {
session = s;
grab_input = 0;
if (has_video) {
has_video = false;
setCursor(Qt::ArrowCursor);
emit hasVideoChanged();
}
if(session && exit_app_on_stream_exit)
{
connect(session, &StreamSession::ConnectedChanged, this, [this]() {
if (session->IsConnected())
connect(session, &StreamSession::SessionQuit, qGuiApp, &QGuiApplication::quit);
});
}
});
connect(backend, &QmlBackend::windowTypeUpdated, this, &QmlMainWindow::updateWindowType);

Expand Down

0 comments on commit 88c9f9b

Please sign in to comment.