Skip to content

Commit

Permalink
fix: dock will not auto hide after set size
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Jan 30, 2024
1 parent 2b81011 commit a1ceaad
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 69 deletions.
137 changes: 68 additions & 69 deletions frame/util/multiscreenworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "multiscreenworker.h"
#include "constants.h"
#include "mainwindow.h"
#include "taskmanager/taskmanager.h"
#include "utils.h"

#include "displaymanager.h"
#include "traymainwindow.h"
#include "mainwindow.h"
#include "menuworker.h"
#include "windowmanager.h"
#include "dockitemmanager.h"
#include "dockscreen.h"
#include "docksettings.h"
#include "mainwindow.h"
#include "menuworker.h"
#include "traymainwindow.h"
#include "utils.h"
#include "windowmanager.h"

#include <QWidget>
#include <QScreen>
#include <qpa/qplatformnativeinterface.h>
#include <qpa/qplatformscreen.h>

#include <QDBusConnection>
#include <QEvent>
#include <QGuiApplication>
#include <QMenu>
#include <QRegion>
#include <QScreen>
#include <QSequentialAnimationGroup>
#include <QVariantAnimation>
#include <QWidget>
#include <QX11Info>
#include <QDBusConnection>
#include <QGuiApplication>
#include <QMenu>

#include <qpa/qplatformscreen.h>
#include <qpa/qplatformnativeinterface.h>

const QString MonitorsSwitchTime = "monitorsSwitchTime";
const QString OnlyShowPrimary = "onlyShowPrimary";
Expand Down Expand Up @@ -62,9 +60,7 @@ MultiScreenWorker::MultiScreenWorker(QObject *parent)
QMetaObject::invokeMethod(this, &MultiScreenWorker::initDisplayData, Qt::QueuedConnection);
}

MultiScreenWorker::~MultiScreenWorker()
{
}
MultiScreenWorker::~MultiScreenWorker() { }

void MultiScreenWorker::updateDaemonDockSize(const int &dockSize)
{
Expand Down Expand Up @@ -142,11 +138,12 @@ void MultiScreenWorker::onExtralRegionMonitorChanged(int x, int y, const QString

void MultiScreenWorker::updateDisplay()
{
//1、屏幕停靠信息,
//2、任务栏当前显示在哪个屏幕也需要更新
//3、任务栏高度或宽度调整的拖拽区域,
//4、通知窗管的任务栏显示区域信息,
//5、通知后端的任务栏显示区域信息
tryToHideDock();
// 1、屏幕停靠信息,
// 2、任务栏当前显示在哪个屏幕也需要更新
// 3、任务栏高度或宽度调整的拖拽区域,
// 4、通知窗管的任务栏显示区域信息,
// 5、通知后端的任务栏显示区域信息
if (DIS_INS->screens().size() == 0) {
qWarning() << "No Screen Can Display.";
return;
Expand Down Expand Up @@ -318,7 +315,9 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor()
const static int flags = Motion | Button | Key;
const static int monitorHeight = static_cast<int>(15 * qApp->devicePixelRatio());
// 后端认为的任务栏大小(无缩放因素影响)
const int realDockSize = int((m_displayMode == DisplayMode::Fashion ? m_windowFashionSize + 20 : m_windowEfficientSize) * qApp->devicePixelRatio());
const int realDockSize = int((m_displayMode == DisplayMode::Fashion ? m_windowFashionSize + 20
: m_windowEfficientSize)
* qApp->devicePixelRatio());

// 任务栏唤起区域
m_monitorRectList.clear();
Expand All @@ -337,35 +336,32 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor()
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + monitorHeight;
}
break;
} break;
case Bottom: {
monitorRect.x1 = screenRect.x();
monitorRect.y1 = screenRect.y() + screenRect.height() - monitorHeight;
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
case Left: {
monitorRect.x1 = screenRect.x();
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + monitorHeight;
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
case Right: {
monitorRect.x1 = screenRect.x() + screenRect.width() - monitorHeight;
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
}

if (!m_monitorRectList.contains(monitorRect)) {
m_monitorRectList << monitorRect;
#ifdef QT_DEBUG
qDebug() << "监听区域:" << monitorRect.x1 << monitorRect.y1 << monitorRect.x2 << monitorRect.y2;
qDebug() << "监听区域:" << monitorRect.x1 << monitorRect.y1 << monitorRect.x2
<< monitorRect.y2;
#endif
}
}
Expand All @@ -386,29 +382,25 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor()
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + realDockSize;
}
break;
} break;
case Bottom: {
monitorRect.x1 = screenRect.x();
monitorRect.y1 = screenRect.y() + screenRect.height() - realDockSize;
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
case Left: {
monitorRect.x1 = screenRect.x();
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + realDockSize;
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
case Right: {
monitorRect.x1 = screenRect.x() + screenRect.width() - realDockSize;
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
}

if (!m_extralRectList.contains(monitorRect)) {
Expand Down Expand Up @@ -439,35 +431,30 @@ void MultiScreenWorker::onRequestUpdateRegionMonitor()
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + monitHeight;
}
break;
} break;
case Bottom: {
monitorRect.x1 = screenRect.x();
monitorRect.y1 = screenRect.y() + screenRect.height() - monitHeight;
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
case Left: {
monitorRect.x1 = screenRect.x();
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + monitHeight;
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
case Right: {
monitorRect.x1 = screenRect.x() + screenRect.width() - monitHeight;
monitorRect.y1 = screenRect.y();
monitorRect.x2 = screenRect.x() + screenRect.width();
monitorRect.y2 = screenRect.y() + screenRect.height();
}
break;
} break;
}

if (!m_touchRectList.contains(monitorRect)) {
m_touchRectList << monitorRect;
}

}

m_registerKey = m_eventInter->RegisterAreas(m_monitorRectList, flags);
Expand Down Expand Up @@ -522,7 +509,7 @@ void MultiScreenWorker::onRequestUpdateMonitorInfo()
void MultiScreenWorker::onRequestDelayShowDock()
{
// 移动Dock至相应屏相应位置
if (testState(LauncherDisplay))//启动器显示,则dock不显示
if (testState(LauncherDisplay)) // 启动器显示,则dock不显示
return;

// 复制模式.不需要响应切换屏幕
Expand All @@ -548,7 +535,7 @@ void MultiScreenWorker::onRequestDelayShowDock()

void MultiScreenWorker::initMembers()
{
m_monitorUpdateTimer->setInterval(100);
m_monitorUpdateTimer->setInterval(1000);
m_monitorUpdateTimer->setSingleShot(true);

m_delayWakeTimer->setSingleShot(true);
Expand Down Expand Up @@ -591,16 +578,16 @@ void MultiScreenWorker::initConnection()

void MultiScreenWorker::initDockMode()
{
onPositionChanged(DockSettings::instance()->getPositionMode());
onDisplayModeChanged(DockSettings::instance()->getDisplayMode());
onHideModeChanged(DockSettings::instance()->getHideMode());
onHideStateChanged(TaskManager::instance()->getHideState());
onOpacityChanged(m_appearanceInter? m_appearanceInter->opacity(): DEFAULTOPACITY);
onPositionChanged(DockSettings::instance()->getPositionMode());
onDisplayModeChanged(DockSettings::instance()->getDisplayMode());
onHideModeChanged(DockSettings::instance()->getHideMode());
onHideStateChanged(TaskManager::instance()->getHideState());
onOpacityChanged(m_appearanceInter? m_appearanceInter->opacity(): DEFAULTOPACITY);

DockItem::setDockPosition(m_position);
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
DockItem::setDockDisplayMode(m_displayMode);
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
DockItem::setDockPosition(m_position);
qApp->setProperty(PROP_POSITION, QVariant::fromValue(m_position));
DockItem::setDockDisplayMode(m_displayMode);
qApp->setProperty(PROP_DISPLAY_MODE, QVariant::fromValue(m_displayMode));
}

/**
Expand Down Expand Up @@ -793,20 +780,20 @@ bool MultiScreenWorker::onScreenEdge(const QString &screenName, const QPoint &po
{
QScreen *screen = DIS_INS->screen(screenName);
if (screen) {
const QRect r { screen->geometry() };
const QRect rect { r.topLeft(), r.size() *screen->devicePixelRatio() };
const QRect r{ screen->geometry() };
const QRect rect{ r.topLeft(), r.size() * screen->devicePixelRatio() };

// 除了要判断鼠标的x坐标和当前区域的位置外,还需要判断当前的坐标的y坐标是否在任务栏的区域内
// 因为有如下场景:任务栏在左侧,双屏幕屏幕上下拼接,此时鼠标沿着最左侧x=0的位置移动到另外一个屏幕
// 如果不判断y坐标的话,此时就认为鼠标在当前任务栏的边缘,导致任务栏在这种状况下没有跟随鼠标
if ((rect.x() == point.x() || rect.x() + rect.width() == point.x())
&& point.y() >= rect.top() && point.y() <= rect.bottom()) {
&& point.y() >= rect.top() && point.y() <= rect.bottom()) {
return true;
}

// 同上,不过此时屏幕是左右拼接,任务栏位于上方或者下方
if ((rect.y() == point.y() || rect.y() + rect.height() == point.y())
&& point.x() >= rect.left() && point.x() <= rect.right()) {
&& point.x() >= rect.left() && point.x() <= rect.right()) {
return true;
}
}
Expand All @@ -818,9 +805,8 @@ const QPoint MultiScreenWorker::rawXPosition(const QPoint &scaledPos)
{
QScreen const *screen = Utils::screenAtByScaled(scaledPos);

return screen ? screen->geometry().topLeft() +
(scaledPos - screen->geometry().topLeft()) *
screen->devicePixelRatio()
return screen ? screen->geometry().topLeft()
+ (scaledPos - screen->geometry().topLeft()) * screen->devicePixelRatio()
: scaledPos;
}

Expand Down Expand Up @@ -957,3 +943,16 @@ void MultiScreenWorker::tryToShowDock(int eventX, int eventY)
}
}
}

void MultiScreenWorker::tryToHideDock()
{
if (hideMode() == HideMode::KeepShowing) {
return;
}

auto mousePos = QCursor::pos();
const QString &currentScreen = DOCK_SCREEN->current();
if (isCursorOut(mousePos.x(), mousePos.y())) {
Q_EMIT requestPlayAnimation(currentScreen, m_position, Dock::AniAction::Hide);
}
}
1 change: 1 addition & 0 deletions frame/util/multiscreenworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private slots:
void reInitDisplayData();

void tryToShowDock(int eventX, int eventY);
void tryToHideDock();
void changeDockPosition(QString fromScreen, QString toScreen, const Position &fromPos, const Position &toPos);

void resetDockScreen();
Expand Down

0 comments on commit a1ceaad

Please sign in to comment.