diff --git a/frame/dbus/dbusxmousearea.cpp b/frame/dbus/dbusxmousearea.cpp deleted file mode 100644 index 1fce0b7ec..000000000 --- a/frame/dbus/dbusxmousearea.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd. - * - * Author: sbw - * - * Maintainer: sbw - * - * 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 3 of the License, or - * 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, see . - */ - -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -c DBusXMouseArea -p dbusxmousearea com.deepin.api.XMouseArea.xml - * - * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#include "dbusxmousearea.h" - -/* - * Implementation of interface class DBusXMouseArea - */ - -DBusXMouseArea::DBusXMouseArea(QObject *parent) - : QDBusAbstractInterface("com.deepin.api.XMouseArea", "/com/deepin/api/XMouseArea", staticInterfaceName(), QDBusConnection::sessionBus(), parent) -{ - QDBusConnection::sessionBus().connect(this->service(), this->path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", "sa{sv}as", this, SLOT(__propertyChanged__(QDBusMessage))); -} - -DBusXMouseArea::~DBusXMouseArea() -{ - QDBusConnection::sessionBus().disconnect(service(), path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", "sa{sv}as", this, SLOT(propertyChanged(QDBusMessage))); -} - diff --git a/frame/dbus/dbusxmousearea.h b/frame/dbus/dbusxmousearea.h deleted file mode 100644 index d1a54fc80..000000000 --- a/frame/dbus/dbusxmousearea.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd. - * - * Author: sbw - * - * Maintainer: sbw - * - * 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 3 of the License, or - * 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, see . - */ - -/* - * This file was generated by qdbusxml2cpp version 0.8 - * Command line was: qdbusxml2cpp -c DBusXMouseArea -p dbusxmousearea com.deepin.api.XMouseArea.xml - * - * qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * Do not edit! All changes made to it will be lost. - */ - -#ifndef DBUSXMOUSEAREA_H_1441764668 -#define DBUSXMOUSEAREA_H_1441764668 - -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Proxy class for interface com.deepin.api.XMouseArea - */ -class DBusXMouseArea: public QDBusAbstractInterface -{ - Q_OBJECT - - Q_SLOT void __propertyChanged__(const QDBusMessage &msg) - { - QList arguments = msg.arguments(); - if (3 != arguments.count()) { - return; - } - QString interfaceName = msg.arguments().at(0).toString(); - if (interfaceName != "com.deepin.api.XMouseArea") { - return; - } - QVariantMap changedProps = qdbus_cast(arguments.at(1).value()); - QStringList keys = changedProps.keys(); - foreach(const QString & prop, keys) { - const QMetaObject *self = metaObject(); - for (int i = self->propertyOffset(); i < self->propertyCount(); ++i) { - QMetaProperty p = self->property(i); - if (p.name() == prop) { - Q_EMIT p.notifySignal().invoke(this); - } - } - } - } -public: - static inline const char *staticInterfaceName() - { - return "com.deepin.api.XMouseArea"; - } - -public: - explicit DBusXMouseArea(QObject *parent = 0); - - ~DBusXMouseArea(); - -public Q_SLOTS: // METHODS - inline QDBusPendingReply RegisterFullScreen() - { - QList argumentList; - return asyncCallWithArgumentList(QStringLiteral("RegisterFullScreen"), argumentList); - } - - inline QDBusPendingReply RegisterArea(const qint32 x1, const qint32 y1, const qint32 x2, const qint32 y2, const qint32 flag) - { - QList argumentList; - argumentList << x1 << y1 << x2 << y2 << flag; - return asyncCallWithArgumentList(QStringLiteral("RegisterArea"), argumentList); - } - - inline QDBusPendingReply<> UnregisterArea(const QString &in0) - { - QList argumentList; - argumentList << QVariant::fromValue(in0); - return asyncCallWithArgumentList(QStringLiteral("UnregisterArea"), argumentList); - } - -Q_SIGNALS: // SIGNALS - void ButtonRelease(int button, int x, int y, const QString &id); -// begin property changed signals -}; - -namespace com -{ -namespace deepin -{ -namespace api -{ -typedef ::DBusXMouseArea XMouseArea; -} -} -} -#endif diff --git a/frame/frame.pro b/frame/frame.pro index ec8739424..12c80fd7f 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -31,7 +31,6 @@ SOURCES += main.cpp \ controller/dockpluginscontroller.cpp \ util/imagefactory.cpp \ util/dockpopupwindow.cpp \ - dbus/dbusxmousearea.cpp \ item/stretchitem.cpp \ item/placeholderitem.cpp \ controller/dockpluginloader.cpp \ @@ -63,7 +62,6 @@ HEADERS += \ controller/dockpluginscontroller.h \ util/imagefactory.h \ util/dockpopupwindow.h \ - dbus/dbusxmousearea.h \ item/stretchitem.h \ item/placeholderitem.h \ controller/dockpluginloader.h \ diff --git a/frame/util/dockpopupwindow.cpp b/frame/util/dockpopupwindow.cpp index 86dd1cca2..88abd764d 100644 --- a/frame/util/dockpopupwindow.cpp +++ b/frame/util/dockpopupwindow.cpp @@ -27,15 +27,13 @@ DWIDGET_USE_NAMESPACE -const int MOUSE_BUTTON(1 << 1); - DockPopupWindow::DockPopupWindow(QWidget *parent) : DArrowRectangle(ArrowBottom, parent), m_model(false), m_acceptDelayTimer(new QTimer(this)), - m_mouseInter(new DBusXMouseArea(this)), + m_regionInter(new DRegionMonitor(this)), m_displayInter(new DBusDisplay(this)) { m_acceptDelayTimer->setSingleShot(true); @@ -52,6 +50,7 @@ DockPopupWindow::DockPopupWindow(QWidget *parent) connect(m_acceptDelayTimer, &QTimer::timeout, this, &DockPopupWindow::accept); connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged); + connect(m_regionInter, &DRegionMonitor::buttonPress, this, &DockPopupWindow::onGlobMouseRelease); } DockPopupWindow::~DockPopupWindow() @@ -82,11 +81,11 @@ void DockPopupWindow::show(const QPoint &pos, const bool model) show(pos.x(), pos.y()); - if (!model && !m_mouseAreaKey.isEmpty()) - unRegisterMouseEvent(); - - if (model && m_mouseAreaKey.isEmpty()) - registerMouseEvent(); + const bool regionRegistered = m_regionInter->registered(); + if (!m_model && regionRegistered) + m_regionInter->unregisterRegion(); + else if (m_model && !regionRegistered) + m_regionInter->registerRegion(); } void DockPopupWindow::show(const int x, const int y) @@ -98,8 +97,8 @@ void DockPopupWindow::show(const int x, const int y) void DockPopupWindow::hide() { - if (!m_mouseAreaKey.isEmpty()) - unRegisterMouseEvent(); + if (m_regionInter->registered()) + m_regionInter->unregisterRegion(); DArrowRectangle::hide(); } @@ -128,69 +127,29 @@ void DockPopupWindow::enterEvent(QEvent *e) setFocus(Qt::ActiveWindowFocusReason); } -void DockPopupWindow::mousePressEvent(QMouseEvent *e) -{ - DArrowRectangle::mousePressEvent(e); - -// if (e->button() == Qt::LeftButton) -// m_acceptDelayTimer->start(); -} - bool DockPopupWindow::eventFilter(QObject *o, QEvent *e) { if (o != getContent() || e->type() != QEvent::Resize) return false; // FIXME: ensure position move after global mouse release event - QTimer::singleShot(100, this, [this] {if (isVisible()) show(m_lastPoint, m_model);}); + QTimer::singleShot(100, this, [this] { if (isVisible()) show(m_lastPoint, m_model); }); return false; } -void DockPopupWindow::globalMouseRelease(int button, int x, int y, const QString &id) +void DockPopupWindow::onGlobMouseRelease(const QPoint &mousePos, const int flag) { - Q_UNUSED(button); - // button_left -// if (button != 1) -// return; - - if (id != m_mouseAreaKey) - return; - + Q_UNUSED(flag); Q_ASSERT(m_model); - const auto ratio = devicePixelRatioF(); const QRect rect = QRect(pos(), size()); - const QPoint pos = QPoint(x / ratio, y / ratio); - - if (rect.contains(pos)) + if (rect.contains(mousePos)) return; emit accept(); - unRegisterMouseEvent(); -} - -void DockPopupWindow::registerMouseEvent() -{ - if (!m_mouseAreaKey.isEmpty()) - return; - - // only regist mouse button event - m_mouseAreaKey = m_mouseInter->RegisterArea(0, 0, m_displayInter->screenWidth(), m_displayInter->screenHeight(), MOUSE_BUTTON); - - connect(m_mouseInter, &DBusXMouseArea::ButtonRelease, this, &DockPopupWindow::globalMouseRelease, Qt::QueuedConnection); -} - -void DockPopupWindow::unRegisterMouseEvent() -{ - if (m_mouseAreaKey.isEmpty()) - return; - - disconnect(m_mouseInter, &DBusXMouseArea::ButtonRelease, this, &DockPopupWindow::globalMouseRelease); - - m_mouseInter->UnregisterArea(m_mouseAreaKey); - m_mouseAreaKey.clear(); + m_regionInter->unregisterRegion(); } void DockPopupWindow::compositeChanged() diff --git a/frame/util/dockpopupwindow.h b/frame/util/dockpopupwindow.h index e958af80a..9cd02913f 100644 --- a/frame/util/dockpopupwindow.h +++ b/frame/util/dockpopupwindow.h @@ -22,10 +22,10 @@ #ifndef DOCKPOPUPWINDOW_H #define DOCKPOPUPWINDOW_H -#include "dbus/dbusxmousearea.h" #include "dbus/dbusdisplay.h" #include +#include #include DWIDGET_USE_NAMESPACE @@ -53,23 +53,19 @@ signals: protected: void showEvent(QShowEvent *e); void enterEvent(QEvent *e); - void mousePressEvent(QMouseEvent *e); bool eventFilter(QObject *o, QEvent *e); private slots: - void globalMouseRelease(int button, int x, int y, const QString &id); - void registerMouseEvent(); - void unRegisterMouseEvent(); + void onGlobMouseRelease(const QPoint &mousePos, const int flag); void compositeChanged(); private: bool m_model; QPoint m_lastPoint; - QString m_mouseAreaKey; QTimer *m_acceptDelayTimer; - DBusXMouseArea *m_mouseInter; + DRegionMonitor *m_regionInter; DBusDisplay *m_displayInter; DWindowManagerHelper *m_wmHelper; };