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.
This commit is contained in:
Martin Gräßlin 2012-02-16 11:30:28 +01:00
parent f53e5d1efe
commit cb5360c53d
3 changed files with 49 additions and 0 deletions

View file

@ -422,6 +422,11 @@ void AuroraeClient::themeChanged()
m_scene->addItem(m_item);
}
int AuroraeClient::doubleClickInterval() const
{
return QApplication::doubleClickInterval();
}
} // namespace Aurorae
extern "C"

View file

@ -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();

View file

@ -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()
}
}