From 3eb29d47ddc62cb7ce1c43c52bbb0571d41afa55 Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Mon, 23 Feb 2015 18:07:31 +0900 Subject: [PATCH] menu: modified Always on Top feature on Ubuntu To apply to Always on Top, all of the child windows which are higher than parent window in z-order should be getting a "ABOVE" state. Change-Id: I720913846189a0236c074e3694b5e1b4d81807db Signed-off-by: GiWoong Kim --- tizen/src/ui/dockingconview.cpp | 2 +- tizen/src/ui/mainwindow.cpp | 4 ++ tizen/src/ui/menu/aboutdialog.cpp | 4 +- tizen/src/ui/menu/contextmenu.cpp | 62 ++++++++---------------- tizen/src/ui/menu/contextmenu.h | 1 + tizen/src/ui/menu/detailedinfodialog.cpp | 2 +- tizen/src/ui/skinview.cpp | 3 +- tizen/src/ui/uiutil.cpp | 45 +++++++++++++++++ tizen/src/ui/uiutil.h | 10 ++++ 9 files changed, 86 insertions(+), 47 deletions(-) diff --git a/tizen/src/ui/dockingconview.cpp b/tizen/src/ui/dockingconview.cpp index dee2b3f1b5..a6bfb630ac 100644 --- a/tizen/src/ui/dockingconview.cpp +++ b/tizen/src/ui/dockingconview.cpp @@ -86,7 +86,7 @@ void DockingConView::mousePressEvent(QMouseEvent *event) } if (event->button() == Qt::LeftButton) { - QWidget *win = ((QWidget *)parent->parent()); + QWidget *win = parent->parentWidget(); grabPos = event->globalPos(); eventPos = event->pos(); diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index d2486804c0..78f3ba9fee 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -268,6 +268,10 @@ void MainWindow::openController(int index, int dockPos) /* Some part of QGLWidget's surface might be lost on Windows when view changing. * So, we need an additional updating for display. */ display->update(); + +#ifdef CONFIG_LINUX + popupMenu->slotTopMost(getUIState()->isOnTop()); +#endif } void MainWindow::closeController() diff --git a/tizen/src/ui/menu/aboutdialog.cpp b/tizen/src/ui/menu/aboutdialog.cpp index 14f5d165b5..8531396ad7 100644 --- a/tizen/src/ui/menu/aboutdialog.cpp +++ b/tizen/src/ui/menu/aboutdialog.cpp @@ -34,7 +34,7 @@ #define URL_TIZEN_ORG "https://developer.tizen.org"; AboutDialog::AboutDialog(QWidget *parent) : - QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint) + QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) { setWindowTitle("About Emulator"); @@ -109,7 +109,7 @@ void AboutDialog::showEvent(QShowEvent *event) { Q_UNUSED(event) - QWidget *win = ((QWidget *)this->parent()); + QWidget *win = parentWidget(); move(win->geometry().center().x() - (geometry().size().width() / 2), win->geometry().center().y() - (geometry().size().height() / 2)); } diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index d5f75c27a2..cdab0c8fa4 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -33,16 +33,10 @@ #include "contextmenu.h" #include "emulator_common.h" #include "mainwindow.h" +#include "uiutil.h" #include "menu/advancedmenuitem.h" #include "menu/scalemenuitem.h" -#ifdef CONFIG_WIN32 -#include -#elif defined (CONFIG_LINUX) -#include -#include -#endif - ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent) { this->parent = (MainWindow *)parent; @@ -422,50 +416,32 @@ void ContextMenu::slotDetailedInfo() } infoDialog->show(); + +#ifdef CONFIG_LINUX + slotTopMost(parent->getUIState()->isOnTop()); +#endif } void ContextMenu::slotTopMost(bool on) { qDebug("stays on top : %s", on? "on" : "off"); -#ifdef CONFIG_WIN32 - HWND hWnd = (HWND)parent->winId(); - HWND hWndInsertAfter = ((on == true) ? HWND_TOPMOST : HWND_NOTOPMOST); - SetWindowPos(hWnd, hWndInsertAfter, parent->pos().x(), parent->pos().y(), 0, 0, SWP_NOSIZE); -#elif defined(CONFIG_LINUX) - Display* display = XOpenDisplay(NULL); - if (display == NULL) { - qDebug("Error: XOpenDisplay() Failed. Always on top failed."); - return; - } +#ifdef CONFIG_LINUX + /* On Ubuntu, all of the child windows which are higher than parent window in z-order + * should be getting a "ABOVE" state. */ - XClientMessageEvent event; - memset(&event, 0, sizeof(event)); - event.type = ClientMessage; - event.window = parent->winId(); - event.message_type = XInternAtom(display, "_NET_WM_STATE", False); - event.format = 32; - event.data.l[0] = on ? 1 : 0; /* 1:_NET_WM_STATE_ADD, 0:_NET_WM_STATE_REMOVE */ - event.data.l[1] = XInternAtom(display, "_NET_WM_STATE_ABOVE", False); - event.data.l[2] = 0; /* unused */ - event.data.l[3] = 0; - event.data.l[4] = 0; - - XSendEvent(display, DefaultRootWindow(display), False, - SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&event); - XFlush(display); - - XCloseDisplay(display); -#elif defined(CONFIG_DARWIN) - if (on == true) { - parent->setWindowFlags(parent->windowFlags() | Qt::WindowStaysOnTopHint); - } else { - parent->setWindowFlags(parent->windowFlags() & ~(Qt::WindowStaysOnTopHint)); + QWidgetList list = QApplication::topLevelWidgets(); + QWidget *widget = NULL; + for (int i = 0; i < list.count(); i++) { + widget = list.at(i); + if (widget->isWindow() && widget->parentWidget() == parent) { + UIUtil::setTopMost(widget, on); + } } - - parent->show(); #endif + UIUtil::setTopMost(parent, on); + actionTopMost->setChecked(on); parent->getUIState()->setOnTop(on); } @@ -756,6 +732,10 @@ void ContextMenu::slotAbout() } aboutDialog->show(); + +#ifdef CONFIG_LINUX + slotTopMost(parent->getUIState()->isOnTop()); +#endif } void ContextMenu::slotForceClose() diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h index 7d48f21c2c..a776b3b0f1 100644 --- a/tizen/src/ui/menu/contextmenu.h +++ b/tizen/src/ui/menu/contextmenu.h @@ -33,6 +33,7 @@ #include +#include "emulator_common.h" #include "detailedinfodialog.h" #include "aboutdialog.h" #include "screenshotdialog.h" diff --git a/tizen/src/ui/menu/detailedinfodialog.cpp b/tizen/src/ui/menu/detailedinfodialog.cpp index 5152857932..7c86f0cf49 100644 --- a/tizen/src/ui/menu/detailedinfodialog.cpp +++ b/tizen/src/ui/menu/detailedinfodialog.cpp @@ -221,7 +221,7 @@ void DetailedInfoDialog::showEvent(QShowEvent *event) { Q_UNUSED(event) - QWidget *win = ((QWidget *)this->parent()); + QWidget *win = parentWidget(); move(win->geometry().center().x() - (geometry().size().width() / 2), win->geometry().center().y() - (geometry().size().height() / 2)); } diff --git a/tizen/src/ui/skinview.cpp b/tizen/src/ui/skinview.cpp index 33bbc0dc57..1f0c316da9 100644 --- a/tizen/src/ui/skinview.cpp +++ b/tizen/src/ui/skinview.cpp @@ -106,8 +106,7 @@ void SkinView::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { //qDebug("grab"); - QWidget *win = ((QWidget *) this->parent()); - grabWinPos = win->pos(); + grabWinPos = parentWidget()->pos(); grabPos = event->globalPos(); } diff --git a/tizen/src/ui/uiutil.cpp b/tizen/src/ui/uiutil.cpp index ab2959a149..1e50c73a78 100644 --- a/tizen/src/ui/uiutil.cpp +++ b/tizen/src/ui/uiutil.cpp @@ -39,3 +39,48 @@ QRect UIUtil::getHostScreenBounds() return QApplication::screens().at( QApplication::desktop()->primaryScreen())->virtualGeometry(); } + +void UIUtil::setTopMost(QWidget *widget, bool on) +{ + if (widget == NULL) { + return; + } + +#ifdef CONFIG_WIN32 + HWND hWnd = (HWND)widget->winId(); + HWND hWndInsertAfter = ((on == true) ? HWND_TOPMOST : HWND_NOTOPMOST); + SetWindowPos(hWnd, hWndInsertAfter, widget->pos().x(), widget->pos().y(), 0, 0, SWP_NOSIZE); +#elif defined(CONFIG_LINUX) + Display* display = XOpenDisplay(NULL); + if (display == NULL) { + qDebug("Error: XOpenDisplay() Failed. Always on top failed."); + return; + } + + XClientMessageEvent event; + memset(&event, 0, sizeof(event)); + event.type = ClientMessage; + event.window = widget->winId(); + event.message_type = XInternAtom(display, "_NET_WM_STATE", False); + event.format = 32; + event.data.l[0] = on ? 1 : 0; /* 1:_NET_WM_STATE_ADD, 0:_NET_WM_STATE_REMOVE */ + event.data.l[1] = XInternAtom(display, "_NET_WM_STATE_ABOVE", False); + event.data.l[2] = 0; /* unused */ + event.data.l[3] = 0; + event.data.l[4] = 0; + + XSendEvent(display, DefaultRootWindow(display), False, + SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&event); + XFlush(display); + + XCloseDisplay(display); +#elif defined(CONFIG_DARWIN) + if (on == true) { + widget->setWindowFlags(widget->windowFlags() | Qt::WindowStaysOnTopHint); + } else { + widget->setWindowFlags(widget->windowFlags() & ~(Qt::WindowStaysOnTopHint)); + } + + widget->show(); +#endif +} diff --git a/tizen/src/ui/uiutil.h b/tizen/src/ui/uiutil.h index b7e20d01c1..8edd7a3bb1 100644 --- a/tizen/src/ui/uiutil.h +++ b/tizen/src/ui/uiutil.h @@ -35,12 +35,22 @@ #include #include +#include "emulator_common.h" + +#ifdef CONFIG_WIN32 +#include +#elif defined (CONFIG_LINUX) +#include +#include +#endif + class UIUtil { public: UIUtil(); static QRect getHostScreenBounds(); + static void setTopMost(QWidget *widget, bool on); }; #endif // UIUTIL_H -- 2.34.1