Start the SDL window on the same display as the Qt UI was displayed on

This commit is contained in:
Cameron Gutman 2018-09-05 15:15:53 -07:00
parent 4df9d6b20a
commit 856318f947
3 changed files with 45 additions and 27 deletions

View file

@ -1,6 +1,7 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Window 2.2
import Session 1.0 import Session 1.0
@ -69,7 +70,7 @@ Item {
session.displayLaunchWarning.connect(displayLaunchWarning) session.displayLaunchWarning.connect(displayLaunchWarning)
// Run the streaming session to completion // Run the streaming session to completion
session.exec() session.exec(Screen.virtualX, Screen.virtualY)
// Show the Qt window again after streaming // Show the Qt window again after streaming
window.visible = true window.visible = true

View file

@ -274,7 +274,9 @@ Session::Session(NvComputer* computer, NvApp& app)
m_VideoDecoder(nullptr), m_VideoDecoder(nullptr),
m_DecoderLock(0), m_DecoderLock(0),
m_NeedsIdr(false), m_NeedsIdr(false),
m_AudioDisabled(false) m_AudioDisabled(false),
m_DisplayOriginX(0),
m_DisplayOriginY(0)
{ {
qDebug() << "Server GPU:" << m_Computer->gpuModel; qDebug() << "Server GPU:" << m_Computer->gpuModel;
@ -539,22 +541,31 @@ void Session::getWindowDimensions(bool fullScreen,
displayIndex = SDL_GetWindowDisplayIndex(m_Window); displayIndex = SDL_GetWindowDisplayIndex(m_Window);
SDL_assert(displayIndex >= 0); SDL_assert(displayIndex >= 0);
} }
// If there's a display matching this exact resolution, pick that // Create our window on the same display that Qt's UI
// one (for native full-screen streaming). Otherwise, assume // was being displayed on.
// display 0 for now. TODO: Default to the screen that the Qt window is on else {
else if (fullScreen) {
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
SDL_DisplayMode mode;
if (StreamUtils::getRealDesktopMode(i, &mode) &&
m_ActiveVideoWidth == mode.w &&
m_ActiveVideoHeight == mode.h) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Found exact resolution match on display: %d", "Qt UI screen is at (%d,%d)",
m_DisplayOriginX, m_DisplayOriginY);
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
SDL_Rect displayBounds;
if (SDL_GetDisplayBounds(i, &displayBounds) == 0) {
if (displayBounds.x == m_DisplayOriginX &&
displayBounds.y == m_DisplayOriginY) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"SDL found matching display %d",
i); i);
displayIndex = i; displayIndex = i;
break; break;
} }
} }
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"SDL_GetDisplayBounds(%d) failed: %s",
i, SDL_GetError());
}
}
} }
SDL_Rect usableBounds; SDL_Rect usableBounds;
@ -567,17 +578,18 @@ void Session::getWindowDimensions(bool fullScreen,
if (m_Window != nullptr) { if (m_Window != nullptr) {
int top, left, bottom, right; int top, left, bottom, right;
if (SDL_GetWindowBordersSize(m_Window, &top, &left, &bottom, &right) < 0) { if (SDL_GetWindowBordersSize(m_Window, &top, &left, &bottom, &right) == 0) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to get window border size");
return;
}
x += left; x += left;
y += top; y += top;
width -= left + right; width -= left + right;
height -= top + bottom; height -= top + bottom;
}
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Unable to get window border size: %s",
SDL_GetError());
}
// If the stream window can fit within the usable drawing area with 1:1 // If the stream window can fit within the usable drawing area with 1:1
// scaling, do that rather than filling the screen. // scaling, do that rather than filling the screen.
@ -652,8 +664,11 @@ void Session::toggleFullscreen()
} }
} }
void Session::exec() void Session::exec(int displayOriginX, int displayOriginY)
{ {
m_DisplayOriginX = displayOriginX;
m_DisplayOriginY = displayOriginY;
// Check for validation errors/warnings and emit // Check for validation errors/warnings and emit
// signals for them, if appropriate // signals for them, if appropriate
if (!validateLaunch()) { if (!validateLaunch()) {

View file

@ -19,7 +19,7 @@ class Session : public QObject
public: public:
explicit Session(NvComputer* computer, NvApp& app); explicit Session(NvComputer* computer, NvApp& app);
Q_INVOKABLE void exec(); Q_INVOKABLE void exec(int displayOriginX, int displayOriginY);
static static
bool isHardwareDecodeAvailable(StreamingPreferences::VideoDecoderSelection vds, bool isHardwareDecodeAvailable(StreamingPreferences::VideoDecoderSelection vds,
@ -113,6 +113,8 @@ private:
bool m_NeedsIdr; bool m_NeedsIdr;
bool m_AudioDisabled; bool m_AudioDisabled;
Uint32 m_FullScreenFlag; Uint32 m_FullScreenFlag;
int m_DisplayOriginX;
int m_DisplayOriginY;
int m_ActiveVideoFormat; int m_ActiveVideoFormat;
int m_ActiveVideoWidth; int m_ActiveVideoWidth;