diff --git a/containments/desktop/package/contents/ui/FolderView.qml b/containments/desktop/package/contents/ui/FolderView.qml --- a/containments/desktop/package/contents/ui/FolderView.qml +++ b/containments/desktop/package/contents/ui/FolderView.qml @@ -310,6 +310,8 @@ } if (!hoveredItem || hoveredItem.blank || gridView.currentIndex == -1 || gridView.ctrlPressed || gridView.shiftPressed) { + // Bug 357367: Replay mouse event, so containment actions assigned to left mouse button work + Folder.MouseEventFaker.sendEvent(plasmoid, mouse); return; } diff --git a/containments/desktop/plugins/folder/CMakeLists.txt b/containments/desktop/plugins/folder/CMakeLists.txt --- a/containments/desktop/plugins/folder/CMakeLists.txt +++ b/containments/desktop/plugins/folder/CMakeLists.txt @@ -14,6 +14,7 @@ viewpropertiesmenu.cpp wheelinterceptor.cpp shortcut.cpp + mouseeventfaker.cpp ) install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/private/desktopcontainment/folder) diff --git a/containments/desktop/plugins/folder/folderplugin.cpp b/containments/desktop/plugins/folder/folderplugin.cpp --- a/containments/desktop/plugins/folder/folderplugin.cpp +++ b/containments/desktop/plugins/folder/folderplugin.cpp @@ -32,9 +32,17 @@ #include "viewpropertiesmenu.h" #include "wheelinterceptor.h" #include "shortcut.h" +#include "mouseeventfaker.h" #include +static QObject *mouseEventFakerSingletonProvider(QQmlEngine *engine, QJSEngine *jsEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(jsEngine) + return new MouseEventFaker(); +} + void FolderPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.private.desktopcontainment.folder")); @@ -52,5 +60,6 @@ qmlRegisterType(uri, 0, 1, "ViewPropertiesMenu"); qmlRegisterType(uri, 0, 1, "WheelInterceptor"); qmlRegisterType(uri, 0, 1, "ShortCut"); + qmlRegisterSingletonType(uri, 0, 1, "MouseEventFaker", mouseEventFakerSingletonProvider); } diff --git a/containments/desktop/plugins/folder/mouseeventfaker.h b/containments/desktop/plugins/folder/mouseeventfaker.h new file mode 100644 --- /dev/null +++ b/containments/desktop/plugins/folder/mouseeventfaker.h @@ -0,0 +1,34 @@ +/************************************************************************** + * Copyright (C) 2017 Kai Uwe Broulik * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#pragma once + +#include + +class MouseEventFaker : public QObject +{ + Q_OBJECT + +public: + explicit MouseEventFaker(QObject *parent = nullptr); + ~MouseEventFaker() override; + + Q_INVOKABLE void sendEvent(QObject *target, QObject *mouseEvent) const; +}; + diff --git a/containments/desktop/plugins/folder/mouseeventfaker.cpp b/containments/desktop/plugins/folder/mouseeventfaker.cpp new file mode 100644 --- /dev/null +++ b/containments/desktop/plugins/folder/mouseeventfaker.cpp @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2017 Kai Uwe Broulik * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * + ***************************************************************************/ + +#include "mouseeventfaker.h" + +#include +#include + +MouseEventFaker::MouseEventFaker(QObject *parent) : QObject(parent) +{ +} + +MouseEventFaker::~MouseEventFaker() = default; + +void MouseEventFaker::sendEvent(QObject *target, QObject *mouseEvent) const +{ + if (!target || !mouseEvent) { + return; + } + + QMouseEvent event(QEvent::MouseButtonPress, + QPointF(mouseEvent->property("x").toReal(), mouseEvent->property("y").toReal()), + static_cast(mouseEvent->property("button").toInt()), + static_cast(mouseEvent->property("buttons").toInt()), + static_cast(mouseEvent->property("modifiers").toInt())); + qApp->sendEvent(target, &event); +}