Skip to content

Commit

Permalink
chore: adjust x11 wake area
Browse files Browse the repository at this point in the history
adjust wake area

log: as title
  • Loading branch information
tsic404 authored and deepin-bot[bot] committed Nov 7, 2024
1 parent 2a8f8a2 commit 232e43a
Show file tree
Hide file tree
Showing 9 changed files with 439 additions and 431 deletions.
204 changes: 115 additions & 89 deletions panels/dock/dockhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,78 +20,31 @@ DockHelper::DockHelper(DockPanel *parent)
m_hideTimer->setSingleShot(true);
m_showTimer->setSingleShot(true);

connect(m_hideTimer, &QTimer::timeout, this, [this, parent]() {
if (parent->hideMode() == KeepShowing)
return;

for (auto enter : m_enters) {
if (enter)
return;
}

parent->setHideState(Hide);
});

connect(m_showTimer, &QTimer::timeout, this, [this, parent]() {
bool res = false;
for (auto enter : m_enters) {
res |= enter;
}

if (res)
parent->setHideState(Show);
});

auto initAreas = [this, parent]() {
// clear old area
for (auto area : m_areas) {
area->close();
delete area;
}

m_areas.clear();
qApp->disconnect(this);

if (!parent->rootObject())
return;

// init areas
for (auto screen : qApp->screens()) {
m_areas.insert(screen, createArea(screen));
}

connect(qApp, &QGuiApplication::screenAdded, this, [this](QScreen *screen) {
if (m_areas.contains(screen))
return;
m_areas.insert(screen, createArea(screen));
});

connect(qApp, &QGuiApplication::screenRemoved, this, [this](QScreen *screen) {
if (!m_areas.contains(screen))
return;

destroyArea(m_areas.value(screen));
m_areas.remove(screen);
});

// init state
updateAllDockWakeArea();
};
qApp->installEventFilter(this);
QMetaObject::invokeMethod(this, &DockHelper::initAreas, Qt::QueuedConnection);
QMetaObject::invokeMethod(this, &DockHelper::checkNeedShowOrNot, Qt::QueuedConnection);

connect(parent, &DockPanel::rootObjectChanged, this, initAreas);
connect(parent, &DockPanel::rootObjectChanged, this, &DockHelper::initAreas);
connect(parent, &DockPanel::showInPrimaryChanged, this, &DockHelper::updateAllDockWakeArea);
connect(parent, &DockPanel::hideStateChanged, this, &DockHelper::updateAllDockWakeArea);
connect(parent, &DockPanel::positionChanged, this, [this](Position pos) {
for (auto area : m_areas) {
std::for_each(m_areas.begin(), m_areas.end(), [pos](const auto &area) {
if (!area)
continue;

return;
area->updateDockWakeArea(pos);
}
});
});

qApp->installEventFilter(this);
QMetaObject::invokeMethod(this, initAreas);
connect(m_hideTimer, &QTimer::timeout, this, &DockHelper::checkNeedHideOrNot);
connect(m_showTimer, &QTimer::timeout, this, &DockHelper::checkNeedShowOrNot);

connect(this, &DockHelper::isWindowOverlapChanged, this, [this](bool overlap) {
if (overlap) {
m_hideTimer->start();
} else {
m_showTimer->start();
}
});
}

bool DockHelper::eventFilter(QObject *watched, QEvent *event)
Expand Down Expand Up @@ -170,58 +123,131 @@ void DockHelper::leaveScreen()
m_hideTimer->start();
}

DockWakeUpArea *DockHelper::createArea(QScreen *screen)
{
return new DockWakeUpArea(screen, this);
}

void DockHelper::destroyArea(DockWakeUpArea *area)
{
if (area) {
area->close();
delete area;
}
}

void DockHelper::updateAllDockWakeArea()
{
for (auto screen : m_areas.keys()) {
auto area = m_areas.value(screen);
if (nullptr == area)
continue;

area->updateDockWakeArea(parent()->position());
if (wakeUpAreaNeedShowOnThisScreen(screen)) {
area->open();
area->updateDockWakeArea(parent()->position());
} else {
area->close();
}
}
}

DockPanel* DockHelper::parent()
void DockHelper::checkNeedHideOrNot()
{
return static_cast<DockPanel *>(QObject::parent());
bool needHide;
switch (parent()->hideMode()) {
case KeepShowing: {
// KeepShow. current activeWindow is maximized.
needHide = currentActiveWindowMaximized();
break;
}
case SmartHide: {
// SmartHide. window overlap.
needHide = isWindowOverlap();
break;
}
case KeepHidden: {
// only any enter
needHide = true;
break;
}
}

// any enter will not make hide
for (auto enter : m_enters) {
needHide &= !enter;
}

if (needHide)
parent()->setHideState(Hide);
}

DockWakeUpArea::DockWakeUpArea(QScreen *screen, DockHelper *helper)
: m_screen(screen)
, m_helper(helper)
void DockHelper::checkNeedShowOrNot()
{
bool needShow;
switch (parent()->hideMode()) {
case KeepShowing: {
// KeepShow. currentWindow is not maximized.
needShow = !currentActiveWindowMaximized();
break;
}
case SmartHide: {
// SmartHide. no window overlap.
needShow = !isWindowOverlap();
break;
}
case KeepHidden: {
// KeepHidden only any enter.
needShow = false;
break;
}
}

for (auto enter : m_enters) {
needShow |= enter;
}

if (needShow)
parent()->setHideState(Show);
}

DockPanel* DockHelper::parent()
{
return static_cast<DockPanel *>(QObject::parent());
}

void DockWakeUpArea::open()
void DockHelper::initAreas()
{
qDebug() << "create wake up area at " << m_screen->name();
// clear old area
for (auto area : m_areas) {
area->close();
delete area;
}

m_areas.clear();
qApp->disconnect(this);

if (!parent()->rootObject())
return;

// init areas
for (auto screen : qApp->screens()) {
m_areas.insert(screen, createArea(screen));
}

connect(qApp, &QGuiApplication::screenAdded, this, [this](QScreen *screen) {
if (m_areas.contains(screen))
return;
m_areas.insert(screen, createArea(screen));
});

connect(qApp, &QGuiApplication::screenRemoved, this, [this](QScreen *screen) {
if (!m_areas.contains(screen))
return;

destroyArea(m_areas.value(screen));
m_areas.remove(screen);
});

// init state
updateAllDockWakeArea();
}

void DockWakeUpArea::close()
DockWakeUpArea::DockWakeUpArea(QScreen *screen, DockHelper *helper)
: m_screen(screen)
, m_helper(helper)
{
qDebug() << "close wake up area at " << m_screen->name();
}

void DockWakeUpArea::updateDockWakeArea(Position pos)
QScreen *DockWakeUpArea::screen()
{
qDebug() << "update wake up area pos to " << pos;
return m_screen;
}
}
41 changes: 21 additions & 20 deletions panels/dock/dockhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@ class DockHelper : public QObject
Q_OBJECT

public:
[[nodiscard]] DockHelper* getHelper(DockPanel* parent);

virtual HideState hideState()
{
return Show;
}

DockHelper(DockPanel *parent);
bool eventFilter(QObject *watched, QEvent *event) override;

public Q_SLOTS:
void enterScreen(QScreen *screen);
void leaveScreen();

virtual void updateDockTriggerArea() = 0;

Q_SIGNALS:
void hideStateChanged();
void isWindowOverlapChanged(bool overlap);
void currentActiveWindowMaximizedChanged(bool maximized);

protected:
bool wakeUpAreaNeedShowOnThisScreen(QScreen *screen);
[[nodiscard]] virtual DockWakeUpArea *createArea(QScreen *screen);
virtual void destroyArea(DockWakeUpArea *area);
DockPanel *parent();
[[nodiscard]] virtual DockWakeUpArea *createArea(QScreen *screen) = 0;
virtual void destroyArea(DockWakeUpArea *area) = 0;

virtual bool currentActiveWindowMaximized() = 0;
virtual bool isWindowOverlap() = 0;

private:
bool wakeUpAreaNeedShowOnThisScreen(QScreen *screen);

void updateAllDockWakeArea();

protected:
DockHelper(DockPanel* parent);
DockPanel* parent();
private Q_SLOTS:
void checkNeedHideOrNot();
void checkNeedShowOrNot();

private:
void initAreas();

private:
QHash<QScreen *, DockWakeUpArea *> m_areas;
Expand All @@ -56,12 +56,13 @@ public Q_SLOTS:
class DockWakeUpArea
{
public:
virtual void open();
virtual void close();
QScreen *screen();
virtual void open() = 0;
virtual void close() = 0;

protected:
explicit DockWakeUpArea(QScreen *screen, DockHelper *helper);
virtual void updateDockWakeArea(Position pos);
virtual void updateDockWakeArea(Position pos) = 0;

protected:
friend class DockHelper;
Expand Down
28 changes: 7 additions & 21 deletions panels/dock/dockpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Q_LOGGING_CATEGORY(dockLog, "dde.shell.dock")

namespace dock {

DockPanel::DockPanel(QObject * parent)
DockPanel::DockPanel(QObject *parent)
: DPanel(parent)
, m_theme(ColorTheme::Dark)
, m_hideState(Hide)
, m_hideState(Show)
, m_dockScreen(nullptr)
, m_loadTrayPlugins(new LoadTrayPlugins(this))
, m_compositorReady(false)
Expand Down Expand Up @@ -153,17 +153,7 @@ bool DockPanel::init()
m_helper = new X11DockHelper(this);
}


connect(m_helper, &DockHelper::hideStateChanged, this, [this](){
if (hideMode() == KeepShowing || m_launcherShown) return;
m_hideState = m_helper->hideState();
Q_EMIT hideStateChanged(m_hideState);
});

QMetaObject::invokeMethod(this, [this, dockDaemonAdaptor]() {
m_hideState = hideMode() == KeepShowing ? Show : m_helper->hideState();
Q_EMIT hideStateChanged(m_hideState);

Q_EMIT dockDaemonAdaptor->FrontendWindowRectChanged(frontendWindowRect());
});

Expand Down Expand Up @@ -301,6 +291,10 @@ void DockPanel::setCompositorReady(bool ready)

HideState DockPanel::hideState()
{
if (m_launcherShown) {
return Show;
}

return m_hideState;
}

Expand Down Expand Up @@ -339,15 +333,7 @@ void DockPanel::launcherVisibleChanged(bool visible)
if (visible == m_launcherShown) return;

m_launcherShown = visible;
if (m_launcherShown) {
setHideState(Show);
} else {
if (hideMode() != KeepShowing) {
setHideState(m_helper->hideState());
} else {
setHideState(Show);
}
}
Q_EMIT hideStateChanged(hideState());
}

void DockPanel::updateDockScreen()
Expand Down
Loading

0 comments on commit 232e43a

Please sign in to comment.