mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 06:30:55 +00:00
Improve support for full-screen exclusive mode
This commit is contained in:
+53
-68
@@ -471,10 +471,14 @@ void Session::getWindowDimensions(bool fullScreen,
|
|||||||
{
|
{
|
||||||
int displayIndex = 0;
|
int displayIndex = 0;
|
||||||
|
|
||||||
|
if (m_Window != nullptr) {
|
||||||
|
displayIndex = SDL_GetWindowDisplayIndex(m_Window);
|
||||||
|
SDL_assert(displayIndex >= 0);
|
||||||
|
}
|
||||||
// If there's a display matching this exact resolution, pick that
|
// If there's a display matching this exact resolution, pick that
|
||||||
// one (for native full-screen streaming). Otherwise, assume
|
// one (for native full-screen streaming). Otherwise, assume
|
||||||
// display 0 for now. TODO: Default to the screen that the Qt window is on
|
// display 0 for now. TODO: Default to the screen that the Qt window is on
|
||||||
if (fullScreen) {
|
else if (fullScreen) {
|
||||||
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
|
for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) {
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
if (SDL_GetCurrentDisplayMode(i, &mode) == 0 &&
|
if (SDL_GetCurrentDisplayMode(i, &mode) == 0 &&
|
||||||
@@ -489,79 +493,44 @@ void Session::getWindowDimensions(bool fullScreen,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Window != nullptr) {
|
SDL_Rect usableBounds;
|
||||||
displayIndex = SDL_GetWindowDisplayIndex(m_Window);
|
if (SDL_GetDisplayUsableBounds(displayIndex, &usableBounds) == 0) {
|
||||||
if (displayIndex < 0) {
|
width = usableBounds.w;
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
height = usableBounds.h;
|
||||||
"SDL_GetWindowDisplayIndex() failed: %s",
|
x = usableBounds.x;
|
||||||
SDL_GetError());
|
y = usableBounds.y;
|
||||||
|
|
||||||
// Assume display 0
|
if (m_Window != nullptr) {
|
||||||
displayIndex = 0;
|
int top, left, bottom, right;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fullScreen) {
|
if (SDL_GetWindowBordersSize(m_Window, &top, &left, &bottom, &right) < 0) {
|
||||||
SDL_DisplayMode currentMode;
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Unable to get window border size");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_GetCurrentDisplayMode(displayIndex, ¤tMode) == 0) {
|
x += left;
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
y += top;
|
||||||
"Using current display mode: %dx%dx%d",
|
|
||||||
currentMode.w, currentMode.h, currentMode.refresh_rate);
|
|
||||||
width = currentMode.w;
|
|
||||||
height = currentMode.h;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"Unable to get current display mode: %s",
|
|
||||||
SDL_GetError());
|
|
||||||
width = m_StreamConfig.width;
|
|
||||||
height = m_StreamConfig.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Full-screen modes always start at the origin
|
width -= left + right;
|
||||||
x = y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex);
|
height -= top + bottom;
|
||||||
}
|
|
||||||
else {
|
|
||||||
SDL_Rect usableBounds;
|
|
||||||
if (SDL_GetDisplayUsableBounds(displayIndex, &usableBounds) == 0) {
|
|
||||||
width = usableBounds.w;
|
|
||||||
height = usableBounds.h;
|
|
||||||
x = usableBounds.x;
|
|
||||||
y = usableBounds.y;
|
|
||||||
|
|
||||||
if (m_Window != nullptr) {
|
// If the stream window can fit within the usable drawing area with 1:1
|
||||||
int top, left, bottom, right;
|
// scaling, do that rather than filling the screen.
|
||||||
|
if (m_StreamConfig.width < width && m_StreamConfig.height < height) {
|
||||||
if (SDL_GetWindowBordersSize(m_Window, &top, &left, &bottom, &right) < 0) {
|
width = m_StreamConfig.width;
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
height = m_StreamConfig.height;
|
||||||
"Unable to get window border size");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
x += left;
|
|
||||||
y += top;
|
|
||||||
|
|
||||||
width -= left + right;
|
|
||||||
height -= top + bottom;
|
|
||||||
|
|
||||||
// If the stream window can fit within the usable drawing area with 1:1
|
|
||||||
// scaling, do that rather than filling the screen.
|
|
||||||
if (m_StreamConfig.width < width && m_StreamConfig.height < height) {
|
|
||||||
width = m_StreamConfig.width;
|
|
||||||
height = m_StreamConfig.height;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
else {
|
||||||
"SDL_GetDisplayUsableBounds() failed: %s",
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
SDL_GetError());
|
"SDL_GetDisplayUsableBounds() failed: %s",
|
||||||
|
SDL_GetError());
|
||||||
|
|
||||||
width = m_StreamConfig.width;
|
width = m_StreamConfig.width;
|
||||||
height = m_StreamConfig.height;
|
height = m_StreamConfig.height;
|
||||||
x = y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex);
|
x = y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(displayIndex);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,8 +663,7 @@ void Session::exec()
|
|||||||
y,
|
y,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
m_Preferences.fullScreen ?
|
0);
|
||||||
SDL_OS_FULLSCREEN_FLAG : 0);
|
|
||||||
if (!m_Window) {
|
if (!m_Window) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"SDL_CreateWindow() failed: %s",
|
"SDL_CreateWindow() failed: %s",
|
||||||
@@ -718,6 +686,16 @@ void Session::exec()
|
|||||||
// creation causes our window to be full screen for some reason
|
// creation causes our window to be full screen for some reason
|
||||||
SDL_SetWindowResizable(m_Window, SDL_TRUE);
|
SDL_SetWindowResizable(m_Window, SDL_TRUE);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Update the window display mode based on our current monitor
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
if (SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(m_Window), &mode) == 0) {
|
||||||
|
SDL_SetWindowDisplayMode(m_Window, &mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enter full screen
|
||||||
|
SDL_SetWindowFullscreen(m_Window, SDL_OS_FULLSCREEN_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
QSvgRenderer svgIconRenderer(QString(":/res/moonlight.svg"));
|
QSvgRenderer svgIconRenderer(QString(":/res/moonlight.svg"));
|
||||||
QImage svgImage(ICON_SIZE, ICON_SIZE, QImage::Format_RGBA8888);
|
QImage svgImage(ICON_SIZE, ICON_SIZE, QImage::Format_RGBA8888);
|
||||||
@@ -816,6 +794,13 @@ void Session::exec()
|
|||||||
// Fall through
|
// Fall through
|
||||||
case SDL_RENDER_DEVICE_RESET:
|
case SDL_RENDER_DEVICE_RESET:
|
||||||
case SDL_RENDER_TARGETS_RESET:
|
case SDL_RENDER_TARGETS_RESET:
|
||||||
|
|
||||||
|
// Update the window display mode based on our current monitor
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
if (SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(m_Window), &mode) == 0) {
|
||||||
|
SDL_SetWindowDisplayMode(m_Window, &mode);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_AtomicLock(&m_DecoderLock);
|
SDL_AtomicLock(&m_DecoderLock);
|
||||||
|
|
||||||
// Destroy the old decoder
|
// Destroy the old decoder
|
||||||
|
|||||||
@@ -441,8 +441,6 @@ bool DXVA2Renderer::initialize(SDL_Window* window, int videoFormat, int width, i
|
|||||||
// D3DCREATE_MULTITHREADED to IDirect3D9::CreateDevice().
|
// D3DCREATE_MULTITHREADED to IDirect3D9::CreateDevice().
|
||||||
SDL_SetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE, "1");
|
SDL_SetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE, "1");
|
||||||
|
|
||||||
// We require full-screen desktop mode to avoid having to enable V-sync
|
|
||||||
// to synchronize frame delivery (which has a much higher latency penalty).
|
|
||||||
m_SdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
m_SdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
if (!m_SdlRenderer) {
|
if (!m_SdlRenderer) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
@@ -452,6 +450,12 @@ bool DXVA2Renderer::initialize(SDL_Window* window, int videoFormat, int width, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Device = SDL_RenderGetD3D9Device(m_SdlRenderer);
|
m_Device = SDL_RenderGetD3D9Device(m_SdlRenderer);
|
||||||
|
if (m_Device == nullptr) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"SDL_RenderGetD3D9Device() failed: %s",
|
||||||
|
SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Draw a black frame until the video stream starts rendering
|
// Draw a black frame until the video stream starts rendering
|
||||||
SDL_SetRenderDrawColor(m_SdlRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
SDL_SetRenderDrawColor(m_SdlRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
|
||||||
|
|||||||
Reference in New Issue
Block a user