From cb5360c53d37bdcc6ddc028568aecee2781b8395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 16 Feb 2012 11:30:28 +0100 Subject: [PATCH] Improve mouse click behavior of Aurorae Menu button The general idea is: single click opens menu, double click closes the window. The problem is that the when the menu is opened after the single click, the menu will eat the second click. So double click will not work. This commit brings back the workaround from Aurorae2. The clicked event is not used at all, but we start a timer on the press event with the doubleClickInterval. If no double click appears during the interval we open the menu, if there is a double click we close the window. The downside of this approach is that there is a slight delay between clicking the menu button and the menu appearing. For that the right click behavior is unchanged. That is right clicking opens the menu instantly and double click to close it, is broken. --- clients/aurorae/src/aurorae.cpp | 5 +++ clients/aurorae/src/aurorae.h | 2 ++ clients/aurorae/src/qml/MenuButton.qml | 42 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index 76eb527240..886df59591 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -422,6 +422,11 @@ void AuroraeClient::themeChanged() m_scene->addItem(m_item); } +int AuroraeClient::doubleClickInterval() const +{ + return QApplication::doubleClickInterval(); +} + } // namespace Aurorae extern "C" diff --git a/clients/aurorae/src/aurorae.h b/clients/aurorae/src/aurorae.h index 8088aaa37f..48211ee770 100644 --- a/clients/aurorae/src/aurorae.h +++ b/clients/aurorae/src/aurorae.h @@ -100,6 +100,7 @@ class AuroraeClient : public KDecorationUnstable Q_PROPERTY(QRect transparentRect READ transparentRect) Q_PROPERTY(int width READ width) Q_PROPERTY(qulonglong windowId READ windowId CONSTANT) + Q_PROPERTY(int doubleClickInterval READ doubleClickInterval) // TODO: window tabs - they suck for dynamic features public: AuroraeClient(KDecorationBridge* bridge, KDecorationFactory* factory); @@ -119,6 +120,7 @@ public: virtual void padding(int &left, int &right, int &top, int &bottom) const; virtual void reset(long unsigned int changed); bool isMaximized() const; + int doubleClickInterval() const; Q_SIGNALS: void activeChanged(); diff --git a/clients/aurorae/src/qml/MenuButton.qml b/clients/aurorae/src/qml/MenuButton.qml index 186df8111e..2f6183c1f0 100644 --- a/clients/aurorae/src/qml/MenuButton.qml +++ b/clients/aurorae/src/qml/MenuButton.qml @@ -23,4 +23,46 @@ DecorationButton { icon: decoration.icon anchors.fill: parent } + Timer { + id: timer + interval: decoration.doubleClickInterval + repeat: false + onTriggered: decoration.menuClicked() + } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onPressed: { + parent.pressed = true; + // we need a timer to figure out whether there is a double click in progress or not + // if we have a "normal" click we want to open the context menu. This would eat our + // second click of the double click. To properly get the double click we have to wait + // the double click delay to ensure that it was only a single click. + if (timer.running) { + timer.stop(); + } else { + timer.start(); + } + } + onReleased: { + parent.pressed = false; + } + onExited: { + if (!parent.pressed) { + return; + } + if (timer.running) { + timer.stop(); + } + parent.pressed = false; + } + onClicked: { + // for right clicks we show the menu instantly + if (mouse.button == Qt.RightButton) { + decoration.menuClicked(); + timer.stop(); + } + } + onDoubleClicked: decoration.closeWindow() + } }