Fix Window.setFocus() unsetting focus if Interface has focus

This commit is contained in:
David Rowe 2018-03-02 15:40:49 +13:00
parent d888e7fd95
commit 287ea8eff2
3 changed files with 12 additions and 3 deletions

View file

@ -7329,6 +7329,16 @@ bool Application::hasFocus() const {
return (QApplication::activeWindow() != nullptr);
}
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();
// Do NOT do the following because it takes focus away from the _displayPlugin.
//window->setFocus();
}
void Application::setMaxOctreePacketsPerSecond(int maxOctreePPS) {
if (maxOctreePPS != _maxOctreePPS) {
_maxOctreePPS = maxOctreePPS;

View file

@ -160,6 +160,7 @@ public:
QRect getRecommendedHUDRect() const;
glm::vec2 getDeviceSize() const;
bool hasFocus() const;
void setFocus();
void showCursor(const Cursor::Icon& cursor);

View file

@ -74,9 +74,7 @@ QScriptValue WindowScriptingInterface::hasFocus() {
void WindowScriptingInterface::setFocus() {
// It's forbidden to call focus() from another thread.
qApp->postLambdaEvent([] {
auto window = qApp->getWindow();
window->activateWindow();
window->setFocus();
qApp->setFocus();
});
}