2017-09-18 14:33:44 +08:00
|
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
#include "dockpopupwindow.h"
|
2021-11-05 21:29:32 +08:00
|
|
|
|
#include "imageutil.h"
|
2021-08-06 17:23:05 +08:00
|
|
|
|
#include "utils.h"
|
2022-11-17 10:49:48 +08:00
|
|
|
|
#include "dbusutil.h"
|
2016-07-15 11:00:55 +08:00
|
|
|
|
|
2016-08-30 15:11:09 +08:00
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopWidget>
|
2020-03-13 12:59:02 +08:00
|
|
|
|
#include <QAccessible>
|
|
|
|
|
#include <QAccessibleEvent>
|
2021-11-05 21:29:32 +08:00
|
|
|
|
#include <QCursor>
|
|
|
|
|
#include <QGSettings>
|
2016-08-30 15:11:09 +08:00
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
DWIDGET_USE_NAMESPACE
|
|
|
|
|
|
|
|
|
|
DockPopupWindow::DockPopupWindow(QWidget *parent)
|
2022-11-17 10:49:48 +08:00
|
|
|
|
: DArrowRectangle(ArrowBottom, parent)
|
|
|
|
|
, m_model(false)
|
|
|
|
|
, m_eventMonitor(new XEventMonitor(xEventMonitorService, xEventMonitorPath, QDBusConnection::sessionBus(), this))
|
|
|
|
|
, m_enableMouseRelease(true)
|
2022-12-15 19:58:43 +08:00
|
|
|
|
, m_extendWidget(nullptr)
|
2016-07-15 11:00:55 +08:00
|
|
|
|
{
|
2020-11-27 16:35:17 +08:00
|
|
|
|
setMargin(0);
|
2017-05-15 10:52:59 +08:00
|
|
|
|
m_wmHelper = DWindowManagerHelper::instance();
|
|
|
|
|
|
|
|
|
|
compositeChanged();
|
|
|
|
|
|
2020-08-18 11:18:00 +08:00
|
|
|
|
setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::WindowDoesNotAcceptFocus);
|
2021-08-06 17:23:05 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
setAttribute(Qt::WA_NativeWindow);
|
2022-02-17 09:55:08 +08:00
|
|
|
|
windowHandle()->setProperty("_d_dwayland_window-type", "override");
|
|
|
|
|
} else {
|
2021-08-06 17:23:05 +08:00
|
|
|
|
setAttribute(Qt::WA_InputMethodEnabled, false);
|
|
|
|
|
}
|
2016-08-11 15:32:48 +08:00
|
|
|
|
|
2017-05-15 10:52:59 +08:00
|
|
|
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &DockPopupWindow::compositeChanged);
|
2022-11-17 10:49:48 +08:00
|
|
|
|
connect(m_eventMonitor, &XEventMonitor::ButtonPress, this, &DockPopupWindow::onButtonPress);
|
|
|
|
|
|
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY)
|
|
|
|
|
QDBusConnection::sessionBus().connect("com.deepin.dde.lockFront", "/com/deepin/dde/lockFront", "com.deepin.dde.lockFront", "Visible", "b", this, SLOT(hide()));
|
2016-07-15 11:00:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
|
DockPopupWindow::~DockPopupWindow()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
bool DockPopupWindow::model() const
|
|
|
|
|
{
|
2018-03-15 11:35:10 +08:00
|
|
|
|
return isVisible() && m_model;
|
2016-07-15 11:00:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
void DockPopupWindow::setContent(QWidget *content)
|
|
|
|
|
{
|
|
|
|
|
QWidget *lastWidget = getContent();
|
|
|
|
|
if (lastWidget)
|
|
|
|
|
lastWidget->removeEventFilter(this);
|
|
|
|
|
content->installEventFilter(this);
|
|
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
|
QAccessibleEvent event(this, QAccessible::NameChanged);
|
|
|
|
|
QAccessible::updateAccessibility(&event);
|
|
|
|
|
|
2020-07-16 06:28:02 +00:00
|
|
|
|
if (!content->objectName().trimmed().isEmpty())
|
|
|
|
|
setAccessibleName(content->objectName() + "-popup");
|
2016-07-28 10:59:21 +08:00
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
DArrowRectangle::setContent(content);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-15 19:58:43 +08:00
|
|
|
|
void DockPopupWindow::setExtendWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
m_extendWidget = widget;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-15 11:00:55 +08:00
|
|
|
|
void DockPopupWindow::show(const QPoint &pos, const bool model)
|
|
|
|
|
{
|
|
|
|
|
m_model = model;
|
2016-07-27 14:08:23 +08:00
|
|
|
|
m_lastPoint = pos;
|
2016-07-15 11:00:55 +08:00
|
|
|
|
|
2017-03-06 09:45:38 +08:00
|
|
|
|
show(pos.x(), pos.y());
|
2016-07-18 10:09:26 +08:00
|
|
|
|
|
2022-11-17 10:49:48 +08:00
|
|
|
|
if (!m_eventKey.isEmpty()) {
|
|
|
|
|
m_eventMonitor->UnregisterArea(m_eventKey);
|
|
|
|
|
m_eventKey.clear();
|
2019-05-30 14:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_model) {
|
2022-11-17 10:49:48 +08:00
|
|
|
|
m_eventKey = m_eventMonitor->RegisterFullScreen();
|
2018-04-26 20:05:54 +08:00
|
|
|
|
}
|
2022-11-17 10:49:48 +08:00
|
|
|
|
|
2022-01-05 15:52:40 +08:00
|
|
|
|
blockButtonRelease();
|
2016-07-18 10:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 09:45:38 +08:00
|
|
|
|
void DockPopupWindow::show(const int x, const int y)
|
|
|
|
|
{
|
2017-03-24 15:55:33 +08:00
|
|
|
|
m_lastPoint = QPoint(x, y);
|
2022-01-05 15:52:40 +08:00
|
|
|
|
blockButtonRelease();
|
2017-03-06 09:45:38 +08:00
|
|
|
|
|
2017-06-30 10:53:48 +08:00
|
|
|
|
DArrowRectangle::show(x, y);
|
2017-03-06 09:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-05 15:52:40 +08:00
|
|
|
|
void DockPopupWindow::blockButtonRelease()
|
|
|
|
|
{
|
|
|
|
|
// 短暂的不处理鼠标release事件,防止出现刚显示又被隐藏的情况
|
|
|
|
|
m_enableMouseRelease = false;
|
|
|
|
|
QTimer::singleShot(10, this, [this] {
|
|
|
|
|
m_enableMouseRelease = true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 15:08:16 +08:00
|
|
|
|
void DockPopupWindow::hide()
|
|
|
|
|
{
|
2022-11-17 10:49:48 +08:00
|
|
|
|
if (!m_eventKey.isEmpty()) {
|
|
|
|
|
m_eventMonitor->UnregisterArea(m_eventKey);
|
|
|
|
|
m_eventKey.clear();
|
|
|
|
|
}
|
2016-07-19 15:08:16 +08:00
|
|
|
|
|
|
|
|
|
DArrowRectangle::hide();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-05 14:33:57 +08:00
|
|
|
|
void DockPopupWindow::showEvent(QShowEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DArrowRectangle::showEvent(e);
|
2021-12-31 15:09:12 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
Utils::updateCursor(this);
|
|
|
|
|
}
|
2016-09-05 14:33:57 +08:00
|
|
|
|
|
2017-12-15 16:47:16 +08:00
|
|
|
|
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
|
2016-09-05 14:33:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-15 19:58:43 +08:00
|
|
|
|
void DockPopupWindow::hideEvent(QHideEvent *event)
|
|
|
|
|
{
|
|
|
|
|
m_extendWidget = nullptr;
|
|
|
|
|
Dtk::Widget::DArrowRectangle::hideEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 10:55:19 +08:00
|
|
|
|
void DockPopupWindow::enterEvent(QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
DArrowRectangle::enterEvent(e);
|
2021-12-31 15:09:12 +08:00
|
|
|
|
if (Utils::IS_WAYLAND_DISPLAY) {
|
|
|
|
|
Utils::updateCursor(this);
|
|
|
|
|
}
|
2016-09-01 10:55:19 +08:00
|
|
|
|
|
2017-12-15 16:47:16 +08:00
|
|
|
|
QTimer::singleShot(1, this, &DockPopupWindow::ensureRaised);
|
2016-09-01 10:55:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (o != getContent() || e->type() != QEvent::Resize)
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-07-27 14:49:29 +08:00
|
|
|
|
// FIXME: ensure position move after global mouse release event
|
2022-11-17 10:49:48 +08:00
|
|
|
|
if (isVisible()) {
|
2018-03-27 17:39:29 +08:00
|
|
|
|
QTimer::singleShot(10, this, [=] {
|
|
|
|
|
// NOTE(sbw): double check is necessary, in this time, the popup maybe already hided.
|
|
|
|
|
if (isVisible())
|
|
|
|
|
show(m_lastPoint, m_model);
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-07-27 14:49:29 +08:00
|
|
|
|
|
2016-07-27 14:08:23 +08:00
|
|
|
|
return false;
|
2016-07-18 10:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 10:52:59 +08:00
|
|
|
|
void DockPopupWindow::compositeChanged()
|
|
|
|
|
{
|
|
|
|
|
if (m_wmHelper->hasComposite())
|
|
|
|
|
setBorderColor(QColor(255, 255, 255, 255 * 0.05));
|
|
|
|
|
else
|
|
|
|
|
setBorderColor(QColor("#2C3238"));
|
|
|
|
|
}
|
2017-12-15 16:47:16 +08:00
|
|
|
|
|
|
|
|
|
void DockPopupWindow::ensureRaised()
|
|
|
|
|
{
|
|
|
|
|
if (isVisible())
|
|
|
|
|
raise();
|
|
|
|
|
}
|
2022-11-17 10:49:48 +08:00
|
|
|
|
|
|
|
|
|
void DockPopupWindow::onButtonPress(int type, int x, int y, const QString &key)
|
|
|
|
|
{
|
|
|
|
|
if (!m_enableMouseRelease)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-11-21 16:24:02 +08:00
|
|
|
|
QRect popupRect(pos() * qApp->devicePixelRatio(), size() * qApp->devicePixelRatio()) ;
|
2022-11-17 10:49:48 +08:00
|
|
|
|
if (popupRect.contains(x, y))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-12-15 19:58:43 +08:00
|
|
|
|
if (m_extendWidget) {
|
|
|
|
|
// 计算额外添加的区域,如果鼠标的点击点在额外的区域内,也无需隐藏
|
|
|
|
|
QPoint extendPoint = m_extendWidget->mapToGlobal(QPoint(0, 0));
|
|
|
|
|
QRect extendRect(extendPoint * qApp->devicePixelRatio(), m_extendWidget->size() * qApp->devicePixelRatio());
|
|
|
|
|
if (extendRect.contains(QPoint(x, y)))
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 10:49:48 +08:00
|
|
|
|
emit accept();
|
|
|
|
|
hide();
|
|
|
|
|
}
|
2023-01-05 17:03:02 +08:00
|
|
|
|
|
|
|
|
|
PopupSwitchWidget::PopupSwitchWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
, m_containerLayout(new QVBoxLayout(this))
|
|
|
|
|
, m_topWidget(nullptr)
|
|
|
|
|
{
|
|
|
|
|
m_containerLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_containerLayout->setSpacing(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PopupSwitchWidget::~PopupSwitchWidget()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PopupSwitchWidget::pushWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
// 首先将界面其他的窗体移除
|
|
|
|
|
for (int i = m_containerLayout->count() - 1; i >= 0; i--) {
|
|
|
|
|
QLayoutItem *item = m_containerLayout->itemAt(i);
|
|
|
|
|
item->widget()->removeEventFilter(this);
|
|
|
|
|
item->widget()->hide();
|
|
|
|
|
m_containerLayout->removeItem(item);
|
|
|
|
|
}
|
|
|
|
|
m_topWidget = widget;
|
|
|
|
|
setFixedSize(widget->size());
|
|
|
|
|
widget->installEventFilter(this);
|
|
|
|
|
m_containerLayout->addWidget(widget);
|
|
|
|
|
widget->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PopupSwitchWidget::eventFilter(QObject *watched, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (watched == m_topWidget && event->type() == QEvent::Resize) {
|
|
|
|
|
setFixedSize(m_topWidget->size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QWidget::eventFilter(watched, event);
|
|
|
|
|
}
|