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 dpiAwareness option to manifest and send physicial viewport size to Spout #3462

Merged
merged 4 commits into from Oct 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/stellarium.exe.manifest
Expand Up @@ -41,8 +41,9 @@
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<asmv3:windowsSettings>
<ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</ms_windowsSettings:dpiAware>
<ms_windowsSettings:dpiAwareness xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</ms_windowsSettings:dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
25 changes: 25 additions & 0 deletions src/StelMainView.cpp
Expand Up @@ -929,8 +929,18 @@ void StelMainView::init()
stelApp->init(configuration);
//this makes sure the app knows how large the window is
connect(stelScene,SIGNAL(sceneRectChanged(QRectF)),stelApp,SLOT(glWindowHasBeenResized(QRectF)));
#ifdef ENABLE_SPOUT
QObject::connect(stelScene, &StelGraphicsScene::sceneRectChanged, [&](const QRectF& rect)
{
stelApp->glPhysicalWindowHasBeenResized(getPhysicalSize(rect));
alex-w marked this conversation as resolved.
Show resolved Hide resolved
});
#endif

//also immediately set the current values
stelApp->glWindowHasBeenResized(stelScene->sceneRect());
#ifdef ENABLE_SPOUT
stelApp->glPhysicalWindowHasBeenResized(getPhysicalSize(stelScene->sceneRect()));
#endif

StelActionMgr *actionMgr = stelApp->getStelActionManager();
actionMgr->addAction("actionSave_Screenshot_Global", N_("Miscellaneous"), N_("Save screenshot"), this, "saveScreenShot()", "Ctrl+S");
Expand Down Expand Up @@ -1346,6 +1356,21 @@ void StelMainView::processOpenGLdiagnosticsAndWarnings(QSettings *conf, QOpenGLC
#endif
}

// Get physical dimensions given the virtual dimensions for the screen where this window is located.
QRectF StelMainView::getPhysicalSize(const QRectF& virtualRect) const
{
auto window = this->window();
if(window)
{
auto pixelRatio = window->devicePixelRatio();
QRectF newRect(virtualRect.x(), virtualRect.y(), virtualRect.width() * pixelRatio, virtualRect.height() * pixelRatio);
return newRect;
}

// If the platform does not support getting the QWindow backing instance of this QWidget
return virtualRect;
}

// Debug info about OpenGL capabilities.
void StelMainView::dumpOpenGLdiagnostics() const
{
Expand Down
2 changes: 2 additions & 0 deletions src/StelMainView.hpp
Expand Up @@ -301,6 +301,8 @@ private slots:
//! Startup diagnostics, providing test for various circumstances of bad OS/OpenGL driver combinations
//! to provide feedback to the user about bad OpenGL drivers.
void processOpenGLdiagnosticsAndWarnings(QSettings *conf, QOpenGLContext* context) const;
//! Get physical dimensions given the virtual dimensions for the screen where this window is located.
QRectF getPhysicalSize(const QRectF& virtualRect) const;

//! The StelMainView singleton
static StelMainView* singleton;
Expand Down
13 changes: 12 additions & 1 deletion src/core/StelApp.cpp
Expand Up @@ -1067,7 +1067,7 @@ void StelApp::draw()
}

/*************************************************************************
Call this when the size of the GL window has changed
Call this when the virtual size of the GL window has changed
*************************************************************************/
void StelApp::glWindowHasBeenResized(const QRectF& rect)
{
Expand All @@ -1091,6 +1091,17 @@ void StelApp::glWindowHasBeenResized(const QRectF& rect)
#endif
}

/*************************************************************************
Call this when the physical size of the GL window has changed
*************************************************************************/
void StelApp::glPhysicalWindowHasBeenResized(const QRectF& rect)
{
#ifdef ENABLE_SPOUT
if (spoutSender)
spoutSender->resize(static_cast<uint>(rect.width()),static_cast<uint>(rect.height()));
#endif
}

// Handle mouse clics
void StelApp::handleClick(QMouseEvent* inputEvent)
{
Expand Down
5 changes: 4 additions & 1 deletion src/core/StelApp.hpp
Expand Up @@ -264,9 +264,12 @@ class StelApp : public QObject
///////////////////////////////////////////////////////////////////////////
// Scriptable methods
public slots:
//! Call this when the size of the GL window has changed.
//! Call this when the virtual size of the GL window has changed.
void glWindowHasBeenResized(const QRectF &rect);

//! Call this when the physical size of the GL window has changed.
void glPhysicalWindowHasBeenResized(const QRectF &rect);

//! Set flag for activating night vision mode.
void setVisionModeNight(bool);
//! Get flag for activating night vision mode.
Expand Down