mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
using DRegionMonitor instead XMouseArea
Change-Id: Ie0e6b3bab7666e30f97d67eb5bebc545b79a480f
This commit is contained in:
parent
c784f3c54c
commit
ffba5070bb
Notes:
Deepin Code Review
2017-09-28 16:12:38 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Thu, 28 Sep 2017 16:12:38 +0800 Reviewed-on: https://cr.deepin.io/26758 Project: dde/dde-dock Branch: refs/heads/master
@ -1,49 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* Author: sbw <sbw@sbw.so>
|
|
||||||
*
|
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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)));
|
|
||||||
}
|
|
||||||
|
|
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
|
|
||||||
*
|
|
||||||
* Author: sbw <sbw@sbw.so>
|
|
||||||
*
|
|
||||||
* Maintainer: sbw <sbw@sbw.so>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 <QtCore/QObject>
|
|
||||||
#include <QtCore/QByteArray>
|
|
||||||
#include <QtCore/QList>
|
|
||||||
#include <QtCore/QMap>
|
|
||||||
#include <QtCore/QString>
|
|
||||||
#include <QtCore/QStringList>
|
|
||||||
#include <QtCore/QVariant>
|
|
||||||
#include <QtDBus/QtDBus>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Proxy class for interface com.deepin.api.XMouseArea
|
|
||||||
*/
|
|
||||||
class DBusXMouseArea: public QDBusAbstractInterface
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_SLOT void __propertyChanged__(const QDBusMessage &msg)
|
|
||||||
{
|
|
||||||
QList<QVariant> 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<QVariantMap>(arguments.at(1).value<QDBusArgument>());
|
|
||||||
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<QString> RegisterFullScreen()
|
|
||||||
{
|
|
||||||
QList<QVariant> argumentList;
|
|
||||||
return asyncCallWithArgumentList(QStringLiteral("RegisterFullScreen"), argumentList);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QDBusPendingReply<QString> RegisterArea(const qint32 x1, const qint32 y1, const qint32 x2, const qint32 y2, const qint32 flag)
|
|
||||||
{
|
|
||||||
QList<QVariant> argumentList;
|
|
||||||
argumentList << x1 << y1 << x2 << y2 << flag;
|
|
||||||
return asyncCallWithArgumentList(QStringLiteral("RegisterArea"), argumentList);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QDBusPendingReply<> UnregisterArea(const QString &in0)
|
|
||||||
{
|
|
||||||
QList<QVariant> 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
|
|
@ -31,7 +31,6 @@ SOURCES += main.cpp \
|
|||||||
controller/dockpluginscontroller.cpp \
|
controller/dockpluginscontroller.cpp \
|
||||||
util/imagefactory.cpp \
|
util/imagefactory.cpp \
|
||||||
util/dockpopupwindow.cpp \
|
util/dockpopupwindow.cpp \
|
||||||
dbus/dbusxmousearea.cpp \
|
|
||||||
item/stretchitem.cpp \
|
item/stretchitem.cpp \
|
||||||
item/placeholderitem.cpp \
|
item/placeholderitem.cpp \
|
||||||
controller/dockpluginloader.cpp \
|
controller/dockpluginloader.cpp \
|
||||||
@ -63,7 +62,6 @@ HEADERS += \
|
|||||||
controller/dockpluginscontroller.h \
|
controller/dockpluginscontroller.h \
|
||||||
util/imagefactory.h \
|
util/imagefactory.h \
|
||||||
util/dockpopupwindow.h \
|
util/dockpopupwindow.h \
|
||||||
dbus/dbusxmousearea.h \
|
|
||||||
item/stretchitem.h \
|
item/stretchitem.h \
|
||||||
item/placeholderitem.h \
|
item/placeholderitem.h \
|
||||||
controller/dockpluginloader.h \
|
controller/dockpluginloader.h \
|
||||||
|
@ -27,15 +27,13 @@
|
|||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
const int MOUSE_BUTTON(1 << 1);
|
|
||||||
|
|
||||||
DockPopupWindow::DockPopupWindow(QWidget *parent)
|
DockPopupWindow::DockPopupWindow(QWidget *parent)
|
||||||
: DArrowRectangle(ArrowBottom, parent),
|
: DArrowRectangle(ArrowBottom, parent),
|
||||||
m_model(false),
|
m_model(false),
|
||||||
|
|
||||||
m_acceptDelayTimer(new QTimer(this)),
|
m_acceptDelayTimer(new QTimer(this)),
|
||||||
|
|
||||||
m_mouseInter(new DBusXMouseArea(this)),
|
m_regionInter(new DRegionMonitor(this)),
|
||||||
m_displayInter(new DBusDisplay(this))
|
m_displayInter(new DBusDisplay(this))
|
||||||
{
|
{
|
||||||
m_acceptDelayTimer->setSingleShot(true);
|
m_acceptDelayTimer->setSingleShot(true);
|
||||||
@ -52,6 +50,7 @@ DockPopupWindow::DockPopupWindow(QWidget *parent)
|
|||||||
|
|
||||||
connect(m_acceptDelayTimer, &QTimer::timeout, this, &DockPopupWindow::accept);
|
connect(m_acceptDelayTimer, &QTimer::timeout, this, &DockPopupWindow::accept);
|
||||||
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
|
||||||
|
connect(m_regionInter, &DRegionMonitor::buttonPress, this, &DockPopupWindow::onGlobMouseRelease);
|
||||||
}
|
}
|
||||||
|
|
||||||
DockPopupWindow::~DockPopupWindow()
|
DockPopupWindow::~DockPopupWindow()
|
||||||
@ -82,11 +81,11 @@ void DockPopupWindow::show(const QPoint &pos, const bool model)
|
|||||||
|
|
||||||
show(pos.x(), pos.y());
|
show(pos.x(), pos.y());
|
||||||
|
|
||||||
if (!model && !m_mouseAreaKey.isEmpty())
|
const bool regionRegistered = m_regionInter->registered();
|
||||||
unRegisterMouseEvent();
|
if (!m_model && regionRegistered)
|
||||||
|
m_regionInter->unregisterRegion();
|
||||||
if (model && m_mouseAreaKey.isEmpty())
|
else if (m_model && !regionRegistered)
|
||||||
registerMouseEvent();
|
m_regionInter->registerRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockPopupWindow::show(const int x, const int y)
|
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()
|
void DockPopupWindow::hide()
|
||||||
{
|
{
|
||||||
if (!m_mouseAreaKey.isEmpty())
|
if (m_regionInter->registered())
|
||||||
unRegisterMouseEvent();
|
m_regionInter->unregisterRegion();
|
||||||
|
|
||||||
DArrowRectangle::hide();
|
DArrowRectangle::hide();
|
||||||
}
|
}
|
||||||
@ -128,69 +127,29 @@ void DockPopupWindow::enterEvent(QEvent *e)
|
|||||||
setFocus(Qt::ActiveWindowFocusReason);
|
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)
|
bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
|
||||||
{
|
{
|
||||||
if (o != getContent() || e->type() != QEvent::Resize)
|
if (o != getContent() || e->type() != QEvent::Resize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// FIXME: ensure position move after global mouse release event
|
// 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;
|
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);
|
Q_UNUSED(flag);
|
||||||
// button_left
|
|
||||||
// if (button != 1)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
if (id != m_mouseAreaKey)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Q_ASSERT(m_model);
|
Q_ASSERT(m_model);
|
||||||
|
|
||||||
const auto ratio = devicePixelRatioF();
|
|
||||||
const QRect rect = QRect(pos(), size());
|
const QRect rect = QRect(pos(), size());
|
||||||
const QPoint pos = QPoint(x / ratio, y / ratio);
|
if (rect.contains(mousePos))
|
||||||
|
|
||||||
if (rect.contains(pos))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit accept();
|
emit accept();
|
||||||
|
|
||||||
unRegisterMouseEvent();
|
m_regionInter->unregisterRegion();
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockPopupWindow::compositeChanged()
|
void DockPopupWindow::compositeChanged()
|
||||||
|
@ -22,10 +22,10 @@
|
|||||||
#ifndef DOCKPOPUPWINDOW_H
|
#ifndef DOCKPOPUPWINDOW_H
|
||||||
#define DOCKPOPUPWINDOW_H
|
#define DOCKPOPUPWINDOW_H
|
||||||
|
|
||||||
#include "dbus/dbusxmousearea.h"
|
|
||||||
#include "dbus/dbusdisplay.h"
|
#include "dbus/dbusdisplay.h"
|
||||||
|
|
||||||
#include <darrowrectangle.h>
|
#include <darrowrectangle.h>
|
||||||
|
#include <dregionmonitor.h>
|
||||||
#include <DWindowManagerHelper>
|
#include <DWindowManagerHelper>
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
@ -53,23 +53,19 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent *e);
|
void showEvent(QShowEvent *e);
|
||||||
void enterEvent(QEvent *e);
|
void enterEvent(QEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
|
||||||
bool eventFilter(QObject *o, QEvent *e);
|
bool eventFilter(QObject *o, QEvent *e);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void globalMouseRelease(int button, int x, int y, const QString &id);
|
void onGlobMouseRelease(const QPoint &mousePos, const int flag);
|
||||||
void registerMouseEvent();
|
|
||||||
void unRegisterMouseEvent();
|
|
||||||
void compositeChanged();
|
void compositeChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_model;
|
bool m_model;
|
||||||
QPoint m_lastPoint;
|
QPoint m_lastPoint;
|
||||||
QString m_mouseAreaKey;
|
|
||||||
|
|
||||||
QTimer *m_acceptDelayTimer;
|
QTimer *m_acceptDelayTimer;
|
||||||
|
|
||||||
DBusXMouseArea *m_mouseInter;
|
DRegionMonitor *m_regionInter;
|
||||||
DBusDisplay *m_displayInter;
|
DBusDisplay *m_displayInter;
|
||||||
DWindowManagerHelper *m_wmHelper;
|
DWindowManagerHelper *m_wmHelper;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user