mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 22:10:25 +02:00
Merge pull request #12635 from ctrlaltdavid/21776
Fix Window hasFocus(), setFocus(), and raiseMainWindow()
This commit is contained in:
commit
f5f4e2a780
9 changed files with 35 additions and 24 deletions
|
@ -7347,10 +7347,35 @@ bool Application::isThrottleRendering() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::hasFocus() const {
|
bool Application::hasFocus() const {
|
||||||
if (_displayPlugin) {
|
bool result = (QApplication::activeWindow() != nullptr);
|
||||||
return getActiveDisplayPlugin()->hasFocus();
|
#if defined(Q_OS_WIN)
|
||||||
|
// On Windows, QWidget::activateWindow() - as called in setFocus() - makes the application's taskbar icon flash but doesn't
|
||||||
|
// take user focus away from their current window. So also check whether the application is the user's current foreground
|
||||||
|
// window.
|
||||||
|
result = result && (HWND)QApplication::activeWindow()->winId() == GetForegroundWindow();
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setFocus() {
|
||||||
|
// Note: Windows doesn't allow a user focus to be taken away from another application. Instead, it changes the color of and
|
||||||
|
// flashes the taskbar icon.
|
||||||
|
auto window = qApp->getWindow();
|
||||||
|
window->activateWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::raise() {
|
||||||
|
auto windowState = qApp->getWindow()->windowState();
|
||||||
|
if (windowState & Qt::WindowMinimized) {
|
||||||
|
if (windowState & Qt::WindowMaximized) {
|
||||||
|
qApp->getWindow()->showMaximized();
|
||||||
|
} else if (windowState & Qt::WindowFullScreen) {
|
||||||
|
qApp->getWindow()->showFullScreen();
|
||||||
|
} else {
|
||||||
|
qApp->getWindow()->showNormal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (QApplication::activeWindow() != nullptr);
|
qApp->getWindow()->raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setMaxOctreePacketsPerSecond(int maxOctreePPS) {
|
void Application::setMaxOctreePacketsPerSecond(int maxOctreePPS) {
|
||||||
|
|
|
@ -161,6 +161,8 @@ public:
|
||||||
QRect getRecommendedHUDRect() const;
|
QRect getRecommendedHUDRect() const;
|
||||||
glm::vec2 getDeviceSize() const;
|
glm::vec2 getDeviceSize() const;
|
||||||
bool hasFocus() const;
|
bool hasFocus() const;
|
||||||
|
void setFocus();
|
||||||
|
void raise();
|
||||||
|
|
||||||
void showCursor(const Cursor::Icon& cursor);
|
void showCursor(const Cursor::Icon& cursor);
|
||||||
|
|
||||||
|
|
|
@ -74,16 +74,14 @@ QScriptValue WindowScriptingInterface::hasFocus() {
|
||||||
void WindowScriptingInterface::setFocus() {
|
void WindowScriptingInterface::setFocus() {
|
||||||
// It's forbidden to call focus() from another thread.
|
// It's forbidden to call focus() from another thread.
|
||||||
qApp->postLambdaEvent([] {
|
qApp->postLambdaEvent([] {
|
||||||
auto window = qApp->getWindow();
|
qApp->setFocus();
|
||||||
window->activateWindow();
|
|
||||||
window->setFocus();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowScriptingInterface::raiseMainWindow() {
|
void WindowScriptingInterface::raiseMainWindow() {
|
||||||
// It's forbidden to call raise() from another thread.
|
// It's forbidden to call raise() from another thread.
|
||||||
qApp->postLambdaEvent([] {
|
qApp->postLambdaEvent([] {
|
||||||
qApp->getWindow()->raise();
|
qApp->raise();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,13 +62,14 @@ public slots:
|
||||||
QScriptValue hasFocus();
|
QScriptValue hasFocus();
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Make the Interface window have focus.
|
* Make the Interface window have focus. On Windows, if Interface doesn't already have focus, the task bar icon flashes to
|
||||||
|
* indicate that Interface wants attention but focus isn't taken away from the application that the user is using.
|
||||||
* @function Window.setFocus
|
* @function Window.setFocus
|
||||||
*/
|
*/
|
||||||
void setFocus();
|
void setFocus();
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Raise the Interface window if it is minimized, and give it focus.
|
* Raise the Interface window if it is minimized. If raised, the window gains focus.
|
||||||
* @function Window.raiseMainWindow
|
* @function Window.raiseMainWindow
|
||||||
*/
|
*/
|
||||||
void raiseMainWindow();
|
void raiseMainWindow();
|
||||||
|
|
|
@ -21,10 +21,6 @@ glm::uvec2 NullDisplayPlugin::getRecommendedRenderSize() const {
|
||||||
return glm::uvec2(100, 100);
|
return glm::uvec2(100, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NullDisplayPlugin::hasFocus() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NullDisplayPlugin::submitFrame(const gpu::FramePointer& frame) {
|
void NullDisplayPlugin::submitFrame(const gpu::FramePointer& frame) {
|
||||||
if (frame) {
|
if (frame) {
|
||||||
_gpuContext->consumeFrameUpdates(frame);
|
_gpuContext->consumeFrameUpdates(frame);
|
||||||
|
|
|
@ -16,7 +16,6 @@ public:
|
||||||
grouping getGrouping() const override { return DEVELOPER; }
|
grouping getGrouping() const override { return DEVELOPER; }
|
||||||
|
|
||||||
glm::uvec2 getRecommendedRenderSize() const override;
|
glm::uvec2 getRecommendedRenderSize() const override;
|
||||||
bool hasFocus() const override;
|
|
||||||
void submitFrame(const gpu::FramePointer& newFrame) override;
|
void submitFrame(const gpu::FramePointer& newFrame) override;
|
||||||
QImage getScreenshot(float aspectRatio = 0.0f) const override;
|
QImage getScreenshot(float aspectRatio = 0.0f) const override;
|
||||||
QImage getSecondaryCameraScreenshot() const override;
|
QImage getSecondaryCameraScreenshot() const override;
|
||||||
|
|
|
@ -831,11 +831,6 @@ glm::uvec2 OpenGLDisplayPlugin::getSurfaceSize() const {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenGLDisplayPlugin::hasFocus() const {
|
|
||||||
auto window = _container->getPrimaryWidget();
|
|
||||||
return window ? window->hasFocus() : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::assertNotPresentThread() const {
|
void OpenGLDisplayPlugin::assertNotPresentThread() const {
|
||||||
Q_ASSERT(QThread::currentThread() != _presentThread);
|
Q_ASSERT(QThread::currentThread() != _presentThread);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,6 @@ protected:
|
||||||
virtual void compositePointer();
|
virtual void compositePointer();
|
||||||
virtual void compositeExtra() {};
|
virtual void compositeExtra() {};
|
||||||
|
|
||||||
virtual bool hasFocus() const override;
|
|
||||||
|
|
||||||
// These functions must only be called on the presentation thread
|
// These functions must only be called on the presentation thread
|
||||||
virtual void customizeContext();
|
virtual void customizeContext();
|
||||||
virtual void uncustomizeContext();
|
virtual void uncustomizeContext();
|
||||||
|
|
|
@ -140,9 +140,6 @@ public:
|
||||||
virtual void setContext(const gpu::ContextPointer& context) final { _gpuContext = context; }
|
virtual void setContext(const gpu::ContextPointer& context) final { _gpuContext = context; }
|
||||||
virtual void submitFrame(const gpu::FramePointer& newFrame) = 0;
|
virtual void submitFrame(const gpu::FramePointer& newFrame) = 0;
|
||||||
|
|
||||||
// Does the rendering surface have current focus?
|
|
||||||
virtual bool hasFocus() const = 0;
|
|
||||||
|
|
||||||
// The size of the rendering target (may be larger than the device size due to distortion)
|
// The size of the rendering target (may be larger than the device size due to distortion)
|
||||||
virtual glm::uvec2 getRecommendedRenderSize() const = 0;
|
virtual glm::uvec2 getRecommendedRenderSize() const = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue