2020-08-05 19:46:15 +08:00
|
|
|
|
/*
|
2021-06-18 17:36:06 +08:00
|
|
|
|
* Copyright (C) 2018 ~ 2020 Deepin Technology Co., Ltd.
|
2020-08-05 19:46:15 +08:00
|
|
|
|
*
|
|
|
|
|
* Author: fanpengcheng <fanpengcheng_cm@deepin.com>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef MULTISCREENWORKER_H
|
|
|
|
|
#define MULTISCREENWORKER_H
|
2020-12-16 17:38:41 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
#include "constants.h"
|
|
|
|
|
#include "utils.h"
|
2020-12-16 17:38:41 +08:00
|
|
|
|
#include "dockitem.h"
|
|
|
|
|
#include "xcb_misc.h"
|
2022-06-22 11:18:29 +08:00
|
|
|
|
#include "dbusutil.h"
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
#include <com_deepin_api_xeventmonitor.h>
|
|
|
|
|
#include <com_deepin_dde_launcher.h>
|
|
|
|
|
|
|
|
|
|
#include <DWindowManagerHelper>
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
2021-05-31 17:37:21 +08:00
|
|
|
|
#include <QFlag>
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
#define WINDOWMARGIN ((m_displayMode == Dock::Efficient) ? 0 : 10)
|
|
|
|
|
#define ANIMATIONTIME 300
|
2020-09-08 19:34:53 +08:00
|
|
|
|
#define FREE_POINT(p) if (p) {\
|
2020-09-15 19:54:47 +08:00
|
|
|
|
delete p;\
|
|
|
|
|
p = nullptr;\
|
|
|
|
|
}\
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
DGUI_USE_NAMESPACE
|
|
|
|
|
/**
|
|
|
|
|
* 多屏功能这部分看着很复杂,其实只需要把握住一个核心:及时更新数据!
|
|
|
|
|
* 之前测试出的诸多问题都是在切换任务栏位置,切换屏幕,主屏更改,分辨率更改等情况发生后
|
|
|
|
|
* 任务栏的鼠标唤醒区域或任务栏的大小没更新或者更新时的大小还是按照原来的屏幕信息计算而来的,
|
|
|
|
|
*/
|
2022-06-22 11:18:29 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
using XEventMonitor = ::com::deepin::api::XEventMonitor;
|
|
|
|
|
using DBusLuncher = ::com::deepin::dde::Launcher;
|
|
|
|
|
|
|
|
|
|
using namespace Dock;
|
|
|
|
|
class QVariantAnimation;
|
|
|
|
|
class QWidget;
|
|
|
|
|
class QTimer;
|
|
|
|
|
class MainWindow;
|
2020-09-15 19:54:47 +08:00
|
|
|
|
class QGSettings;
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
2020-09-08 13:06:32 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief The DockScreen class
|
|
|
|
|
* 保存任务栏的屏幕信息
|
|
|
|
|
*/
|
|
|
|
|
class DockScreen
|
|
|
|
|
{
|
2020-08-05 19:46:15 +08:00
|
|
|
|
public:
|
|
|
|
|
explicit DockScreen(const QString &primary)
|
|
|
|
|
: m_currentScreen(primary)
|
|
|
|
|
, m_lastScreen(primary)
|
|
|
|
|
, m_primary(primary)
|
|
|
|
|
{}
|
2021-06-01 10:14:15 +08:00
|
|
|
|
inline const QString ¤t() const {return m_currentScreen;}
|
|
|
|
|
inline const QString &last() const {return m_lastScreen;}
|
|
|
|
|
inline const QString &primary() const {return m_primary;}
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
void updateDockedScreen(const QString &screenName)
|
|
|
|
|
{
|
|
|
|
|
m_lastScreen = m_currentScreen;
|
|
|
|
|
m_currentScreen = screenName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updatePrimary(const QString &primary)
|
|
|
|
|
{
|
|
|
|
|
m_primary = primary;
|
2020-09-08 19:34:53 +08:00
|
|
|
|
if (m_currentScreen.isEmpty()) {
|
|
|
|
|
updateDockedScreen(primary);
|
|
|
|
|
}
|
2020-08-05 19:46:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_currentScreen;
|
|
|
|
|
QString m_lastScreen;
|
|
|
|
|
QString m_primary;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class MultiScreenWorker : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
|
|
|
|
enum Flag {
|
|
|
|
|
Motion = 1 << 0,
|
|
|
|
|
Button = 1 << 1,
|
|
|
|
|
Key = 1 << 2
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-29 17:22:23 +08:00
|
|
|
|
enum AniAction {
|
|
|
|
|
Show = 0,
|
|
|
|
|
Hide
|
|
|
|
|
};
|
|
|
|
|
|
2021-04-14 17:44:50 +08:00
|
|
|
|
enum RunState {
|
|
|
|
|
ShowAnimationStart = 0x1, // 单次显示动画正在运行状态
|
|
|
|
|
HideAnimationStart = 0x2, // 单次隐藏动画正在运行状态
|
|
|
|
|
ChangePositionAnimationStart = 0x4, // 任务栏切换位置动画运行状态
|
|
|
|
|
AutoHide = 0x8, // 和MenuWorker保持一致,未设置此state时表示菜单已经打开
|
|
|
|
|
MousePress = 0x10, // 当前鼠标是否被按下
|
|
|
|
|
TouchPress = 0x20, // 当前触摸屏下是否按下
|
2021-04-16 11:19:56 +08:00
|
|
|
|
LauncherDisplay = 0x40, // 启动器是否显示
|
2021-08-13 10:31:24 +08:00
|
|
|
|
DockIsShowing = 0x80, // 任务栏正在显示
|
2022-05-12 16:24:54 +08:00
|
|
|
|
DockIsDraging = 0x100, // 任务栏正在拖拽
|
2021-04-14 17:44:50 +08:00
|
|
|
|
|
|
|
|
|
// 如果要添加新的状态,可以在上面添加
|
|
|
|
|
RunState_Mask = 0xffffffff,
|
|
|
|
|
};
|
|
|
|
|
|
2021-05-31 17:37:21 +08:00
|
|
|
|
typedef QFlags<RunState> RunStates;
|
2021-04-14 17:44:50 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
MultiScreenWorker(QWidget *parent, DWindowManagerHelper *helper);
|
|
|
|
|
|
|
|
|
|
void initShow();
|
|
|
|
|
|
2022-06-22 11:18:29 +08:00
|
|
|
|
DockInter *dockInter() { return m_dockInter; }
|
2021-03-20 12:10:45 +08:00
|
|
|
|
|
2021-04-14 17:44:50 +08:00
|
|
|
|
inline bool testState(RunState state) { return (m_state & state); }
|
|
|
|
|
void setStates(RunStates state, bool on = true);
|
|
|
|
|
|
2021-03-20 12:10:45 +08:00
|
|
|
|
inline const QString &lastScreen() { return m_ds.last(); }
|
|
|
|
|
inline const QString &deskScreen() { return m_ds.current(); }
|
|
|
|
|
inline const Position &position() { return m_position; }
|
|
|
|
|
inline const DisplayMode &displayMode() { return m_displayMode; }
|
|
|
|
|
inline const HideMode &hideMode() { return m_hideMode; }
|
|
|
|
|
inline const HideState &hideState() { return m_hideState; }
|
|
|
|
|
inline quint8 opacity() { return m_opacity * 255; }
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
QRect dockRect(const QString &screenName, const Position &pos, const HideMode &hideMode, const DisplayMode &displayMode);
|
|
|
|
|
QRect dockRect(const QString &screenName);
|
2021-10-27 17:15:24 +08:00
|
|
|
|
QRect getDockShowMinGeometry(const QString &screenName, bool withoutScale = false);
|
2020-08-07 23:07:35 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
signals:
|
|
|
|
|
void opacityChanged(const quint8 value) const;
|
|
|
|
|
void displayModeChanegd();
|
|
|
|
|
|
|
|
|
|
// 更新监视区域
|
2020-09-08 13:06:32 +08:00
|
|
|
|
void requestUpdateRegionMonitor(); // 更新监听区域
|
2020-08-08 00:55:02 +08:00
|
|
|
|
void requestUpdateFrontendGeometry(); //!!! 给后端的区域不能为是或宽度为0的区域,否则会带来HideState死循环切换的bug
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void requestNotifyWindowManager();
|
|
|
|
|
void requestUpdatePosition(const Position &fromPos, const Position &toPos);
|
2020-08-10 21:54:17 +08:00
|
|
|
|
void requestUpdateLayout(); // 界面需要根据任务栏更新布局的方向
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void requestUpdateDragArea(); // 更新拖拽区域
|
2020-08-08 00:55:02 +08:00
|
|
|
|
void requestUpdateMonitorInfo(); // 屏幕信息发生变化,需要更新任务栏大小,拖拽区域,所在屏幕,监控区域,通知窗管,通知后端,
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
2020-09-29 17:22:23 +08:00
|
|
|
|
void requestStopShowAni();
|
|
|
|
|
void requestStopHideAni();
|
|
|
|
|
|
2020-10-29 18:08:30 +08:00
|
|
|
|
void requestUpdateDockEntry();
|
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
public slots:
|
|
|
|
|
void onAutoHideChanged(bool autoHide);
|
|
|
|
|
void updateDaemonDockSize(int dockSize);
|
2021-04-12 16:53:03 +08:00
|
|
|
|
void onRequestUpdateRegionMonitor();
|
2022-06-22 11:18:29 +08:00
|
|
|
|
|
|
|
|
|
#ifndef USE_AM
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void handleDbusSignal(QDBusMessage);
|
2022-06-22 11:18:29 +08:00
|
|
|
|
#endif
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
// Region Monitor
|
|
|
|
|
void onRegionMonitorChanged(int x, int y, const QString &key);
|
2020-08-07 23:03:41 +08:00
|
|
|
|
void onExtralRegionMonitorChanged(int x, int y, const QString &key);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
// Animation
|
|
|
|
|
void showAniFinished();
|
|
|
|
|
void hideAniFinished();
|
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
void updateDisplay();
|
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void onWindowSizeChanged(uint value);
|
|
|
|
|
void primaryScreenChanged();
|
2020-08-10 21:54:17 +08:00
|
|
|
|
void updateParentGeometry(const QVariant &value, const Position &pos);
|
|
|
|
|
void updateParentGeometry(const QVariant &value);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
// 任务栏属性变化
|
2022-06-22 11:18:29 +08:00
|
|
|
|
void onPositionChanged(int position);
|
|
|
|
|
void onDisplayModeChanged(int displayMode);
|
|
|
|
|
void onHideModeChanged(int hideMode);
|
|
|
|
|
void onHideStateChanged(int state);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void onOpacityChanged(const double value);
|
|
|
|
|
|
|
|
|
|
// 通知后端任务栏所在位置
|
2020-08-07 23:07:35 +08:00
|
|
|
|
void onRequestUpdateFrontendGeometry();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
void onRequestUpdateLayout();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void onRequestNotifyWindowManager();
|
|
|
|
|
void onRequestUpdatePosition(const Position &fromPos, const Position &toPos);
|
|
|
|
|
void onRequestUpdateMonitorInfo();
|
2021-04-16 11:19:56 +08:00
|
|
|
|
void onRequestDelayShowDock();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
// 触摸手势操作
|
2020-08-18 10:41:14 +08:00
|
|
|
|
void onTouchPress(int type, int x, int y, const QString &key);
|
|
|
|
|
void onTouchRelease(int type, int x, int y, const QString &key);
|
|
|
|
|
|
2021-08-25 21:03:30 +08:00
|
|
|
|
void onDelayAutoHideChanged();
|
|
|
|
|
|
2022-05-27 17:34:02 +08:00
|
|
|
|
// 子部件尺寸发生变化
|
|
|
|
|
void onChildSizeChanged();
|
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
private:
|
2021-03-20 12:10:45 +08:00
|
|
|
|
MainWindow *parent();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
// 初始化数据信息
|
|
|
|
|
void initMembers();
|
2022-05-12 16:24:54 +08:00
|
|
|
|
void initDockMode();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void initConnection();
|
|
|
|
|
void initUI();
|
2020-09-08 19:34:53 +08:00
|
|
|
|
void initDisplayData();
|
|
|
|
|
void reInitDisplayData();
|
2020-09-29 17:22:23 +08:00
|
|
|
|
|
|
|
|
|
void displayAnimation(const QString &screen, const Position &pos, AniAction act);
|
|
|
|
|
void displayAnimation(const QString &screen, AniAction act);
|
2021-03-20 12:10:45 +08:00
|
|
|
|
|
2020-08-18 10:41:14 +08:00
|
|
|
|
void tryToShowDock(int eventX, int eventY);
|
2021-10-18 11:45:51 +08:00
|
|
|
|
void changeDockPosition(QString fromScreen, QString toScreen, const Position &fromPos, const Position &toPos);
|
2021-03-20 12:10:45 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
QString getValidScreen(const Position &pos);
|
2020-09-08 19:34:53 +08:00
|
|
|
|
void resetDockScreen();
|
2021-03-20 12:10:45 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
void checkDaemonDockService();
|
2020-09-08 19:34:53 +08:00
|
|
|
|
void checkXEventMonitorService();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
2021-04-16 11:19:56 +08:00
|
|
|
|
QRect dockRectWithoutScale(const QString &screenName, const Position &pos, const HideMode &hideMode, const DisplayMode &displayMode);
|
|
|
|
|
|
2020-08-12 13:57:33 +08:00
|
|
|
|
QRect getDockShowGeometry(const QString &screenName, const Position &pos, const DisplayMode &displaymode, bool withoutScale = false);
|
|
|
|
|
QRect getDockHideGeometry(const QString &screenName, const Position &pos, const DisplayMode &displaymode, bool withoutScale = false);
|
2021-12-31 15:52:15 +08:00
|
|
|
|
bool isCursorOut(int x, int y);
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
QScreen *screenByName(const QString &screenName);
|
|
|
|
|
bool onScreenEdge(const QString &screenName, const QPoint &point);
|
|
|
|
|
const QPoint rawXPosition(const QPoint &scaledPos);
|
2021-08-25 21:03:30 +08:00
|
|
|
|
static bool isCopyMode();
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QWidget *m_parent;
|
|
|
|
|
DWindowManagerHelper *m_wmHelper;
|
|
|
|
|
|
|
|
|
|
// monitor screen
|
|
|
|
|
XEventMonitor *m_eventInter;
|
2020-08-07 23:03:41 +08:00
|
|
|
|
XEventMonitor *m_extralEventInter;
|
2020-08-18 10:41:14 +08:00
|
|
|
|
XEventMonitor *m_touchEventInter;
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
// DBus interface
|
2022-06-22 11:18:29 +08:00
|
|
|
|
DockInter *m_dockInter;
|
2020-09-08 13:06:32 +08:00
|
|
|
|
DBusLuncher *m_launcherInter;
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
// update monitor info
|
|
|
|
|
QTimer *m_monitorUpdateTimer;
|
2021-03-20 12:10:45 +08:00
|
|
|
|
QTimer *m_delayWakeTimer; // sp3需求,切换屏幕显示延时,默认2秒唤起任务栏
|
2020-09-15 19:54:47 +08:00
|
|
|
|
|
2021-03-20 12:10:45 +08:00
|
|
|
|
DockScreen m_ds; // 屏幕名称信息
|
2020-08-05 19:46:15 +08:00
|
|
|
|
|
|
|
|
|
// 任务栏属性
|
|
|
|
|
double m_opacity;
|
|
|
|
|
Position m_position;
|
|
|
|
|
HideMode m_hideMode;
|
|
|
|
|
HideState m_hideState;
|
|
|
|
|
DisplayMode m_displayMode;
|
2020-09-08 13:06:32 +08:00
|
|
|
|
|
2020-08-05 19:46:15 +08:00
|
|
|
|
/***************不和其他流程产生交互,尽量不要动这里的变量***************/
|
|
|
|
|
QString m_registerKey;
|
2020-08-07 23:03:41 +08:00
|
|
|
|
QString m_extralRegisterKey;
|
2020-08-18 10:41:14 +08:00
|
|
|
|
QString m_touchRegisterKey; // 触控屏唤起任务栏监控区域key
|
2020-09-08 13:06:32 +08:00
|
|
|
|
QPoint m_touchPos; // 触屏按下坐标
|
2020-08-05 19:46:15 +08:00
|
|
|
|
QList<MonitRect> m_monitorRectList; // 监听唤起任务栏区域
|
2020-08-07 23:03:41 +08:00
|
|
|
|
QList<MonitRect> m_extralRectList; // 任务栏外部区域,随m_monitorRectList一起更新
|
2020-08-18 10:41:14 +08:00
|
|
|
|
QList<MonitRect> m_touchRectList; // 监听触屏唤起任务栏区域
|
2020-08-12 13:57:33 +08:00
|
|
|
|
QString m_delayScreen; // 任务栏将要切换到的屏幕名
|
2021-04-14 17:44:50 +08:00
|
|
|
|
RunStates m_state;
|
2020-08-05 19:46:15 +08:00
|
|
|
|
/*****************************************************************/
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // MULTISCREENWORKER_H
|