From fc24452fbf24205657179f990dfbfdcd2cfc3fd9 Mon Sep 17 00:00:00 2001 From: Fabian Bumberger Date: Sat, 18 Jan 2014 18:38:04 +0100 Subject: [QNX] Implement the requestActivate function This allows manually transferring focus from one window to another, if the application has focus. Change-Id: If73ddca6ffbb735eaf4ee9fd322d978f9366fb4c Reviewed-by: Rafael Roquetto --- src/plugins/platforms/qnx/qqnxwindow.cpp | 54 ++++++++++++++++++++++++++++++-- src/plugins/platforms/qnx/qqnxwindow.h | 1 + 2 files changed, 52 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/qnx/qqnxwindow.cpp b/src/plugins/platforms/qnx/qqnxwindow.cpp index fe66d547f3..90b00efc13 100644 --- a/src/plugins/platforms/qnx/qqnxwindow.cpp +++ b/src/plugins/platforms/qnx/qqnxwindow.cpp @@ -202,8 +202,6 @@ void QQnxWindow::setVisible(bool visible) root->updateVisibility(root->m_visible); - window()->requestActivate(); - QWindowSystemInterface::handleExposeEvent(window(), window()->geometry()); if (visible) { @@ -435,9 +433,59 @@ void QQnxWindow::lower() void QQnxWindow::requestActivateWindow() { - // Overwrite the default implementation where the window is activated + QQnxWindow *focusWindow = 0; + if (QGuiApplication::focusWindow()) + focusWindow = static_cast(QGuiApplication::focusWindow()->handle()); + + if (focusWindow == this) + return; + + if (screen()->rootWindow() == this || + (focusWindow && findWindow(focusWindow->nativeHandle()))) { + // If the focus window is a child, we can just set the focus of our own window + // group to our window handle + setFocus(nativeHandle()); + } else { + // In order to receive focus the parent's window group has to give focus to the + // child. If we have several hierarchy layers, we have to do that several times + QQnxWindow *currentWindow = this; + QList windowList; + while (currentWindow) { + windowList.prepend(currentWindow); + // If we find the focus window, we don't have to go further + if (currentWindow == focusWindow) + break; + + if (currentWindow->parent()){ + currentWindow = static_cast(currentWindow->parent()); + } else if (screen()->rootWindow() && + screen()->rootWindow()->m_windowGroupName == currentWindow->m_parentGroupName) { + currentWindow = screen()->rootWindow(); + } else { + currentWindow = 0; + } + } + + // We have to apply the focus from parent to child windows + for (int i = 1; i < windowList.size(); ++i) + windowList.at(i-1)->setFocus(windowList.at(i)->nativeHandle()); + + windowList.last()->setFocus(windowList.last()->nativeHandle()); + } + + screen_flush_context(m_screenContext, 0); } +void QQnxWindow::setFocus(screen_window_t newFocusWindow) +{ + screen_group_t screenGroup = 0; + screen_get_window_property_pv(nativeHandle(), SCREEN_PROPERTY_GROUP, + reinterpret_cast(&screenGroup)); + if (screenGroup) { + screen_set_group_property_pv(screenGroup, SCREEN_PROPERTY_KEYBOARD_FOCUS, + reinterpret_cast(&newFocusWindow)); + } +} void QQnxWindow::setWindowState(Qt::WindowState state) { diff --git a/src/plugins/platforms/qnx/qqnxwindow.h b/src/plugins/platforms/qnx/qqnxwindow.h index 750ce763d2..288ce66087 100644 --- a/src/plugins/platforms/qnx/qqnxwindow.h +++ b/src/plugins/platforms/qnx/qqnxwindow.h @@ -130,6 +130,7 @@ private: void updateZorder(int &topZorder); void updateZorder(screen_window_t window, int &zOrder); void applyWindowState(); + void setFocus(screen_window_t newFocusWindow); screen_window_t m_window; QSize m_bufferSize; -- cgit v1.2.3