2022-09-06 11:36:55 +08:00
|
|
|
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2017-09-18 14:33:44 +08:00
|
|
|
|
2016-06-02 09:46:43 +08:00
|
|
|
#ifndef MAINWINDOW_H
|
|
|
|
#define MAINWINDOW_H
|
|
|
|
|
2020-12-16 17:38:41 +08:00
|
|
|
#include "xcb_misc.h"
|
|
|
|
#include "statusnotifierwatcher_interface.h"
|
|
|
|
#include "mainpanelcontrol.h"
|
|
|
|
#include "multiscreenworker.h"
|
|
|
|
#include "touchsignalmanager.h"
|
2021-11-05 21:29:32 +08:00
|
|
|
#include "imageutil.h"
|
|
|
|
#include "utils.h"
|
2017-03-21 15:40:52 +08:00
|
|
|
|
|
|
|
#include <DPlatformWindowHandle>
|
2017-05-11 10:10:32 +08:00
|
|
|
#include <DWindowManagerHelper>
|
2019-08-22 13:52:02 +08:00
|
|
|
#include <DBlurEffectWidget>
|
2019-10-10 17:21:04 +08:00
|
|
|
#include <DGuiApplicationHelper>
|
2022-04-21 16:19:08 +08:00
|
|
|
#include <DConfig>
|
2020-06-05 16:16:59 +08:00
|
|
|
|
|
|
|
#include <QWidget>
|
2019-08-22 13:52:02 +08:00
|
|
|
|
|
|
|
DWIDGET_USE_NAMESPACE
|
2022-04-21 16:19:08 +08:00
|
|
|
DCORE_USE_NAMESPACE
|
2017-03-21 15:40:52 +08:00
|
|
|
|
2019-08-16 17:44:57 +08:00
|
|
|
class MainPanelControl;
|
2020-06-05 16:16:59 +08:00
|
|
|
class QTimer;
|
2020-08-05 19:46:15 +08:00
|
|
|
class MenuWorker;
|
|
|
|
class DragWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_dragStatus;
|
|
|
|
QPoint m_resizePoint;
|
|
|
|
|
|
|
|
public:
|
2021-05-31 17:37:21 +08:00
|
|
|
explicit DragWidget(QWidget *parent = nullptr)
|
|
|
|
: QWidget(parent)
|
2020-08-05 19:46:15 +08:00
|
|
|
{
|
|
|
|
setObjectName("DragWidget");
|
|
|
|
m_dragStatus = false;
|
|
|
|
}
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
public slots:
|
|
|
|
void onTouchMove(double scaleX, double scaleY)
|
|
|
|
{
|
|
|
|
Q_UNUSED(scaleX);
|
|
|
|
Q_UNUSED(scaleY);
|
|
|
|
|
|
|
|
static QPoint lastPos;
|
|
|
|
QPoint curPos = QCursor::pos();
|
|
|
|
if (lastPos == curPos) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastPos = curPos;
|
|
|
|
qApp->postEvent(this, new QMouseEvent(QEvent::MouseMove, mapFromGlobal(curPos)
|
|
|
|
, QPoint(), curPos, Qt::LeftButton, Qt::LeftButton
|
|
|
|
, Qt::NoModifier, Qt::MouseEventSynthesizedByApplication));
|
|
|
|
}
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
signals:
|
|
|
|
void dragPointOffset(QPoint);
|
|
|
|
void dragFinished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void mousePressEvent(QMouseEvent *event) override
|
|
|
|
{
|
2020-08-18 10:41:14 +08:00
|
|
|
// qt转发的触屏按下信号不进行响应
|
|
|
|
if (event->source() == Qt::MouseEventSynthesizedByQt) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
|
|
|
m_resizePoint = event->globalPos();
|
|
|
|
m_dragStatus = true;
|
|
|
|
this->grabMouse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *) override
|
|
|
|
{
|
|
|
|
if (m_dragStatus) {
|
|
|
|
QPoint offset = QPoint(QCursor::pos() - m_resizePoint);
|
|
|
|
emit dragPointOffset(offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *) override
|
|
|
|
{
|
|
|
|
if (!m_dragStatus)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_dragStatus = false;
|
|
|
|
releaseMouse();
|
|
|
|
emit dragFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
void enterEvent(QEvent *) override
|
|
|
|
{
|
2021-11-05 21:29:32 +08:00
|
|
|
if (Utils::IS_WAYLAND_DISPLAY)
|
|
|
|
updateCursor();
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
QApplication::setOverrideCursor(cursor());
|
|
|
|
}
|
|
|
|
|
|
|
|
void leaveEvent(QEvent *) override
|
|
|
|
{
|
|
|
|
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
|
|
|
}
|
2021-11-05 21:29:32 +08:00
|
|
|
|
|
|
|
void updateCursor()
|
|
|
|
{
|
|
|
|
QString theme = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-name", "bloom").toString();
|
|
|
|
int cursorSize = Utils::SettingValue("com.deepin.xsettings", "/com/deepin/xsettings/", "gtk-cursor-theme-size", 24).toInt();
|
|
|
|
Position position = static_cast<Dock::Position>(qApp->property("position").toInt());
|
|
|
|
|
|
|
|
static QString lastTheme;
|
|
|
|
static int lastPosition = -1;
|
|
|
|
static int lastCursorSize = -1;
|
|
|
|
if (theme != lastTheme || position != lastPosition || cursorSize != lastCursorSize) {
|
|
|
|
lastTheme = theme;
|
|
|
|
lastPosition = position;
|
|
|
|
lastCursorSize = cursorSize;
|
|
|
|
const char* cursorName = (position == Bottom || position == Top) ? "v_double_arrow" : "h_double_arrow";
|
|
|
|
QCursor *newCursor = ImageUtil::loadQCursorFromX11Cursor(theme.toStdString().c_str(), cursorName, cursorSize);
|
2021-11-05 21:45:53 +08:00
|
|
|
if (!newCursor)
|
|
|
|
return;
|
|
|
|
|
2021-11-05 21:29:32 +08:00
|
|
|
setCursor(*newCursor);
|
2021-12-31 15:09:12 +08:00
|
|
|
static QCursor *lastCursor = nullptr;
|
2021-11-05 21:29:32 +08:00
|
|
|
if (lastCursor)
|
|
|
|
delete lastCursor;
|
|
|
|
|
|
|
|
lastCursor = newCursor;
|
|
|
|
}
|
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
};
|
|
|
|
|
2021-04-16 11:19:56 +08:00
|
|
|
class MainWindow : public DBlurEffectWidget
|
2016-06-02 09:46:43 +08:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-06-05 16:16:59 +08:00
|
|
|
explicit MainWindow(QWidget *parent = nullptr);
|
2021-08-25 21:03:30 +08:00
|
|
|
|
2019-08-22 13:52:02 +08:00
|
|
|
void setEffectEnabled(const bool enabled);
|
|
|
|
void setComposite(const bool hasComposite);
|
2020-09-25 21:24:00 +08:00
|
|
|
void setGeometry(const QRect &rect);
|
2021-01-21 15:31:25 +08:00
|
|
|
void sendNotifications();
|
2016-06-02 15:43:57 +08:00
|
|
|
|
2019-08-16 17:44:57 +08:00
|
|
|
friend class MainPanelControl;
|
2018-11-05 11:26:20 +08:00
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
MainPanelControl *panel() {return m_mainPanel;}
|
|
|
|
|
2017-12-05 13:08:17 +08:00
|
|
|
public slots:
|
|
|
|
void launch();
|
2020-10-13 15:35:11 +08:00
|
|
|
void callShow();
|
2021-01-21 15:31:25 +08:00
|
|
|
void relaodPlugins();
|
2017-12-05 13:08:17 +08:00
|
|
|
|
2016-06-02 15:43:57 +08:00
|
|
|
private:
|
2017-12-05 13:08:17 +08:00
|
|
|
using QWidget::show;
|
2020-06-13 19:19:30 +08:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void enterEvent(QEvent *e) override;
|
|
|
|
void dragEnterEvent(QDragEnterEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
2020-08-05 19:46:15 +08:00
|
|
|
void moveEvent(QMoveEvent *event) override;
|
2020-08-07 23:03:54 +08:00
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2016-06-29 16:53:37 +08:00
|
|
|
|
2021-04-12 16:53:03 +08:00
|
|
|
void initMember();
|
2019-01-15 19:54:13 +08:00
|
|
|
void initSNIHost();
|
2016-06-06 10:59:29 +08:00
|
|
|
void initComponents();
|
|
|
|
void initConnections();
|
2016-06-03 16:06:11 +08:00
|
|
|
|
2021-09-22 13:12:27 +08:00
|
|
|
void resizeDockIcon();
|
2017-06-08 15:38:11 +08:00
|
|
|
|
2016-10-14 15:47:43 +08:00
|
|
|
signals:
|
|
|
|
void panelGeometryChanged();
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
public slots:
|
2021-08-25 21:03:30 +08:00
|
|
|
void RegisterDdeSession();
|
2021-11-05 13:10:09 +08:00
|
|
|
void resizeDock(int offset, bool dragging);
|
2021-04-12 16:53:03 +08:00
|
|
|
void resetDragWindow(); // 任务栏调整高度或宽度后需调用此函数
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2016-06-03 16:06:11 +08:00
|
|
|
private slots:
|
2017-05-22 10:38:49 +08:00
|
|
|
void compositeChanged();
|
2017-03-21 15:40:52 +08:00
|
|
|
void adjustShadowMask();
|
|
|
|
|
2019-01-15 19:54:13 +08:00
|
|
|
void onDbusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
|
2019-09-05 11:19:11 +08:00
|
|
|
void onMainWindowSizeChanged(QPoint offset);
|
2019-10-10 17:21:04 +08:00
|
|
|
void themeTypeChanged(DGuiApplicationHelper::ColorType themeType);
|
2020-08-18 10:41:14 +08:00
|
|
|
void touchRequestResizeDock();
|
2019-01-15 19:54:13 +08:00
|
|
|
|
2019-09-16 09:21:48 +08:00
|
|
|
private:
|
2021-05-13 11:39:46 +08:00
|
|
|
MainPanelControl *m_mainPanel; // 任务栏
|
2017-03-27 15:36:37 +08:00
|
|
|
DPlatformWindowHandle m_platformWindowHandle;
|
2017-05-11 10:10:32 +08:00
|
|
|
DWindowManagerHelper *m_wmHelper;
|
2021-05-13 11:39:46 +08:00
|
|
|
MultiScreenWorker *m_multiScreenWorker; // 多屏幕管理
|
2020-08-05 19:46:15 +08:00
|
|
|
MenuWorker *m_menuWorker;
|
|
|
|
QTimer *m_shadowMaskOptimizeTimer;
|
2019-01-15 19:54:13 +08:00
|
|
|
QDBusConnectionInterface *m_dbusDaemonInterface;
|
2021-05-13 11:39:46 +08:00
|
|
|
org::kde::StatusNotifierWatcher *m_sniWatcher; // DBUS状态通知
|
2019-09-05 11:19:11 +08:00
|
|
|
DragWidget *m_dragWidget;
|
2020-08-05 19:46:15 +08:00
|
|
|
|
2020-08-20 17:34:30 +08:00
|
|
|
QString m_sniHostService;
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
bool m_launched;
|
|
|
|
QString m_registerKey;
|
|
|
|
QStringList m_registerKeys;
|
2021-04-12 16:53:03 +08:00
|
|
|
|
|
|
|
QTimer *m_updateDragAreaTimer;
|
2022-04-21 16:19:08 +08:00
|
|
|
QSharedPointer<DConfig> m_dconfig;
|
2016-06-02 09:46:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MAINWINDOW_H
|