mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-02 15:45:21 +00:00
chore: 优化代码,方便维护
部分类中的成员变量过多,不方便理解和阅读,改成状态值,参考QWidget的windowFlag,更方便维护 Log: Change-Id: I0dd02ab14c9f6a6aee4c9a53a9cbad4a9077961d
This commit is contained in:
parent
4c08d38313
commit
aad74ebbbc
@ -51,11 +51,7 @@ MultiScreenWorker::MultiScreenWorker(QWidget *parent, DWindowManagerHelper *help
|
||||
, m_monitorUpdateTimer(new QTimer(this))
|
||||
, m_delayWakeTimer(new QTimer(this))
|
||||
, m_ds(DisplayManager::instance()->primary())
|
||||
, m_showAniStart(false)
|
||||
, m_hideAniStart(false)
|
||||
, m_aniStart(false)
|
||||
, m_autoHide(true)
|
||||
, m_btnPress(false)
|
||||
, m_state(AutoHide)
|
||||
{
|
||||
qInfo() << "init dock screen: " << m_ds.current();
|
||||
|
||||
@ -100,6 +96,21 @@ void MultiScreenWorker::initShow()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MultiScreenWorker::setStates 用于存储一些状态
|
||||
* @param state 标识是哪一种状态,后面有需求可以扩充
|
||||
* @param on 设置状态为true或false
|
||||
*/
|
||||
void MultiScreenWorker::setStates(RunStates state, bool on)
|
||||
{
|
||||
RunState type = static_cast<RunState>(int(state & RunState::RunState_Mask));
|
||||
|
||||
if (on)
|
||||
m_state |= type;
|
||||
else
|
||||
m_state &= ~(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief dockRect
|
||||
* @param screenName 屏幕名
|
||||
@ -144,10 +155,10 @@ QRect MultiScreenWorker::dockRectWithoutScale(const QString &screenName, const P
|
||||
|
||||
void MultiScreenWorker::onAutoHideChanged(bool autoHide)
|
||||
{
|
||||
if (m_autoHide != autoHide) {
|
||||
m_autoHide = autoHide;
|
||||
}
|
||||
if (m_autoHide) {
|
||||
if (testState(AutoHide) != autoHide)
|
||||
setStates(AutoHide, autoHide);
|
||||
|
||||
if (testState(AutoHide)) {
|
||||
/**
|
||||
* 当任务栏由一直隐藏模式切换至一直显示模式时,由于信号先调用的这里,再调用的DBus服务去修改m_hideMode的值,
|
||||
* 导致这里走的是KeepHidden,任务栏表现为直接隐藏了,而不是一直显示。
|
||||
@ -215,7 +226,7 @@ void MultiScreenWorker::handleDbusSignal(QDBusMessage msg)
|
||||
|
||||
void MultiScreenWorker::onRegionMonitorChanged(int x, int y, const QString &key)
|
||||
{
|
||||
if (m_registerKey != key || m_btnPress)
|
||||
if (m_registerKey != key || testState(MousePress))
|
||||
return;
|
||||
|
||||
tryToShowDock(x, y);
|
||||
@ -325,7 +336,7 @@ void MultiScreenWorker::updateParentGeometry(const QVariant &value, const Positi
|
||||
|
||||
void MultiScreenWorker::updateParentGeometry(const QVariant &value)
|
||||
{
|
||||
if (!m_showAniStart && !m_hideAniStart)
|
||||
if (!testState(ShowAnimationStart) && !testState(HideAnimationStart))
|
||||
return;
|
||||
|
||||
updateParentGeometry(value, m_position);
|
||||
@ -956,7 +967,10 @@ void MultiScreenWorker::reInitDisplayData()
|
||||
*/
|
||||
void MultiScreenWorker::displayAnimation(const QString &screen, const Position &pos, AniAction act)
|
||||
{
|
||||
if (!m_autoHide || qApp->property("DRAG_STATE").toBool() || m_aniStart || m_hideAniStart || m_showAniStart)
|
||||
if (!testState(AutoHide) || qApp->property("DRAG_STATE").toBool()
|
||||
|| testState(ChangePositionAnimationStart)
|
||||
|| testState(HideAnimationStart)
|
||||
|| testState(ShowAnimationStart))
|
||||
return;
|
||||
|
||||
QRect mainwindowRect = parent()->geometry();
|
||||
@ -1035,18 +1049,18 @@ void MultiScreenWorker::displayAnimation(const QString &screen, const Position &
|
||||
switch (act) {
|
||||
case AniAction::Show:
|
||||
if (newState == QVariantAnimation::Running && oldState == QVariantAnimation::Stopped) {
|
||||
m_showAniStart = true;
|
||||
setStates(ShowAnimationStart);
|
||||
}
|
||||
if (newState == QVariantAnimation::Stopped && oldState == QVariantAnimation::Running) {
|
||||
m_showAniStart = false;
|
||||
setStates(ShowAnimationStart, false);
|
||||
}
|
||||
break;
|
||||
case AniAction::Hide:
|
||||
if (newState == QVariantAnimation::Running && oldState == QVariantAnimation::Stopped) {
|
||||
m_hideAniStart = true;
|
||||
setStates(HideAnimationStart);
|
||||
}
|
||||
if (newState == QVariantAnimation::Stopped && oldState == QVariantAnimation::Running) {
|
||||
m_hideAniStart = false;
|
||||
setStates(HideAnimationStart, false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1174,7 +1188,7 @@ void MultiScreenWorker::changeDockPosition(QString fromScreen, QString toScreen,
|
||||
});
|
||||
|
||||
connect(group, &QVariantAnimation::finished, this, [ = ] {
|
||||
m_aniStart = false;
|
||||
setStates(ChangePositionAnimationStart, false);
|
||||
|
||||
// 结束之后需要根据确定需要再隐藏
|
||||
emit showAniFinished();
|
||||
@ -1182,7 +1196,7 @@ void MultiScreenWorker::changeDockPosition(QString fromScreen, QString toScreen,
|
||||
emit requestNotifyWindowManager();
|
||||
});
|
||||
|
||||
m_aniStart = true;
|
||||
setStates(ChangePositionAnimationStart);
|
||||
|
||||
group->start(QVariantAnimation::DeleteWhenStopped);
|
||||
}
|
||||
@ -1297,13 +1311,13 @@ void MultiScreenWorker::checkXEventMonitorService()
|
||||
{
|
||||
auto connectionInit = [ = ](XEventMonitor * eventInter, XEventMonitor * extralEventInter, XEventMonitor * touchEventInter) {
|
||||
connect(eventInter, &XEventMonitor::CursorMove, this, &MultiScreenWorker::onRegionMonitorChanged);
|
||||
connect(eventInter, &XEventMonitor::ButtonPress, this, [ = ] {m_btnPress = true;});
|
||||
connect(eventInter, &XEventMonitor::ButtonRelease, this, [ = ] {m_btnPress = false;});
|
||||
connect(eventInter, &XEventMonitor::ButtonPress, this, [ = ] { setStates(MousePress, true); });
|
||||
connect(eventInter, &XEventMonitor::ButtonRelease, this, [ = ] { setStates(MousePress, false); });
|
||||
|
||||
connect(extralEventInter, &XEventMonitor::CursorMove, this, &MultiScreenWorker::onExtralRegionMonitorChanged);
|
||||
|
||||
// 触屏时,后端只发送press、release消息,有move消息则为鼠标,press置false
|
||||
connect(touchEventInter, &XEventMonitor::CursorMove, this, [ = ] {m_touchPress = false;});
|
||||
connect(touchEventInter, &XEventMonitor::CursorMove, this, [ = ] { setStates(TouchPress, false); });
|
||||
connect(touchEventInter, &XEventMonitor::ButtonPress, this, &MultiScreenWorker::onTouchPress);
|
||||
connect(touchEventInter, &XEventMonitor::ButtonRelease, this, &MultiScreenWorker::onTouchRelease);
|
||||
};
|
||||
@ -1478,7 +1492,7 @@ void MultiScreenWorker::onTouchPress(int type, int x, int y, const QString &key)
|
||||
return;
|
||||
}
|
||||
|
||||
m_touchPress = true;
|
||||
setStates(TouchPress);
|
||||
m_touchPos = QPoint(x, y);
|
||||
}
|
||||
|
||||
@ -1489,10 +1503,10 @@ void MultiScreenWorker::onTouchRelease(int type, int x, int y, const QString &ke
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_touchPress) {
|
||||
if (!testState(TouchPress)) {
|
||||
return;
|
||||
}
|
||||
m_touchPress = false;
|
||||
setStates(TouchPress, false);
|
||||
|
||||
// 不从指定方向划入,不进行任务栏唤醒;如当任务栏在下,需从下往上划
|
||||
switch (m_position) {
|
||||
@ -1528,7 +1542,7 @@ void MultiScreenWorker::onTouchRelease(int type, int x, int y, const QString &ke
|
||||
*/
|
||||
void MultiScreenWorker::tryToShowDock(int eventX, int eventY)
|
||||
{
|
||||
if ( qApp->property("DRAG_STATE").toBool() || m_aniStart) {
|
||||
if ( qApp->property("DRAG_STATE").toBool() || testState(ChangePositionAnimationStart)) {
|
||||
qWarning() << "dock is draging or animation is running";
|
||||
return;
|
||||
}
|
||||
@ -1572,7 +1586,7 @@ void MultiScreenWorker::tryToShowDock(int eventX, int eventY)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_showAniStart) {
|
||||
if (testState(ShowAnimationStart)) {
|
||||
qDebug() << "animation is running";
|
||||
return;
|
||||
}
|
||||
|
@ -115,6 +115,20 @@ public:
|
||||
Hide
|
||||
};
|
||||
|
||||
enum RunState {
|
||||
ShowAnimationStart = 0x1, // 单次显示动画正在运行状态
|
||||
HideAnimationStart = 0x2, // 单次隐藏动画正在运行状态
|
||||
ChangePositionAnimationStart = 0x4, // 任务栏切换位置动画运行状态
|
||||
AutoHide = 0x8, // 和MenuWorker保持一致,未设置此state时表示菜单已经打开
|
||||
MousePress = 0x10, // 当前鼠标是否被按下
|
||||
TouchPress = 0x20, // 当前触摸屏下是否按下
|
||||
|
||||
// 如果要添加新的状态,可以在上面添加
|
||||
RunState_Mask = 0xffffffff,
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(RunStates, RunState)
|
||||
|
||||
MultiScreenWorker(QWidget *parent, DWindowManagerHelper *helper);
|
||||
~MultiScreenWorker();
|
||||
|
||||
@ -122,6 +136,9 @@ public:
|
||||
|
||||
DBusDock *dockInter() { return m_dockInter; }
|
||||
|
||||
inline bool testState(RunState state) { return (m_state & state); }
|
||||
void setStates(RunStates state, bool on = true);
|
||||
|
||||
inline const QString &lastScreen() { return m_ds.last(); }
|
||||
inline const QString &deskScreen() { return m_ds.current(); }
|
||||
inline const Position &position() { return m_position; }
|
||||
@ -252,17 +269,12 @@ private:
|
||||
QString m_registerKey;
|
||||
QString m_extralRegisterKey;
|
||||
QString m_touchRegisterKey; // 触控屏唤起任务栏监控区域key
|
||||
bool m_showAniStart; // 动画显示过程正在执行标志
|
||||
bool m_hideAniStart; // 动画隐藏过程正在执行标志
|
||||
bool m_aniStart; // changeDockPosition是否正在运行中
|
||||
bool m_autoHide; // 和MenuWorker保持一致,为false时表示菜单已经打开
|
||||
bool m_btnPress; // 鼠标按下时移动到唤醒区域不应该响应唤醒
|
||||
bool m_touchPress; // 触屏按下
|
||||
QPoint m_touchPos; // 触屏按下坐标
|
||||
QList<MonitRect> m_monitorRectList; // 监听唤起任务栏区域
|
||||
QList<MonitRect> m_extralRectList; // 任务栏外部区域,随m_monitorRectList一起更新
|
||||
QList<MonitRect> m_touchRectList; // 监听触屏唤起任务栏区域
|
||||
QString m_delayScreen; // 任务栏将要切换到的屏幕名
|
||||
RunStates m_state;
|
||||
/*****************************************************************/
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user