1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-12 01:17:55 +03:00

improve View config windows focusOut codepath

This commit is contained in:
Michail Vourlakos 2020-07-11 10:48:56 +03:00
parent 1740c0be91
commit 334a40fff1
8 changed files with 49 additions and 40 deletions

View File

@ -78,6 +78,8 @@ void CanvasConfigView::initParentView(Latte::View *view)
{
SubConfigView::initParentView(view);
rootContext()->setContextProperty(QStringLiteral("primaryConfigView"), m_parent);
updateEnabledBorders();
syncGeometry();
}
@ -117,6 +119,8 @@ void CanvasConfigView::syncGeometry()
bool CanvasConfigView::event(QEvent *e)
{
bool result = SubConfigView::event(e);
switch (e->type()) {
case QEvent::Enter:
case QEvent::MouseButtonPress:
@ -129,7 +133,7 @@ bool CanvasConfigView::event(QEvent *e)
break;
}
return SubConfigView::event(e);
return result;
}
void CanvasConfigView::showEvent(QShowEvent *ev)
@ -169,15 +173,14 @@ void CanvasConfigView::focusOutEvent(QFocusEvent *ev)
const auto *focusWindow = qGuiApp->focusWindow();
if ((focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip)))
|| m_latteView->alternativesIsShown()) {
if (focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip))) {
return;
}
const auto parent = qobject_cast<PrimaryConfigView *>(m_parent);
if (!m_latteView->containsMouse() && parent && !parent->sticker() && !parent->isActive()) {
if (!parent->hasFocus()) {
parent->hideConfigWindow();
}
}

View File

@ -70,9 +70,10 @@ public:
QRect geometryWhenVisible() const;
void hideConfigWindow();
public slots:
Q_INVOKABLE void syncGeometry() override;
Q_INVOKABLE void hideConfigWindow();
signals:
void showSignal();

View File

@ -143,7 +143,7 @@ void PrimaryConfigView::requestActivate()
SubConfigView::requestActivate();
}
void PrimaryConfigView::showPrimaryWindow()
void PrimaryConfigView::showConfigWindow()
{
if (isVisible()) {
return;
@ -154,9 +154,17 @@ void PrimaryConfigView::showPrimaryWindow()
showSecondaryWindow();
}
void PrimaryConfigView::hidePrimaryWindow()
void PrimaryConfigView::hideConfigWindow()
{
hide();
if (m_shellSurface) {
//!NOTE: Avoid crash in wayland environment with qt5.9
close();
} else {
hide();
}
hideCanvasWindow();
hideSecondaryWindow();
}
void PrimaryConfigView::showCanvasWindow()
@ -213,11 +221,11 @@ void PrimaryConfigView::setParentView(Latte::View *view)
//!slide-out delay
QTimer::singleShot(SLIDEOUTINTERVAL, [this, view]() {
initParentView(view);
showPrimaryWindow();
showConfigWindow();
});
} else {
initParentView(view);
showPrimaryWindow();
showConfigWindow();
}
}
@ -430,6 +438,16 @@ void PrimaryConfigView::hideEvent(QHideEvent *ev)
setVisible(false);
}
bool PrimaryConfigView::hasFocus() const
{
bool primaryHasHocus{isActive()};
bool secHasFocus{m_secConfigView && m_secConfigView->isActive()};
bool canvasHasFocus{m_canvasConfigView && m_canvasConfigView->isActive()};
bool viewHasFocus{m_latteView && (m_latteView->containsMouse() || m_latteView->alternativesIsShown())};
return (m_blockFocusLost || viewHasFocus || primaryHasHocus || secHasFocus || canvasHasFocus);
}
void PrimaryConfigView::focusOutEvent(QFocusEvent *ev)
{
Q_UNUSED(ev);
@ -440,15 +458,12 @@ void PrimaryConfigView::focusOutEvent(QFocusEvent *ev)
const auto *focusWindow = qGuiApp->focusWindow();
if (!m_latteView
|| (focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip)))
|| m_latteView->alternativesIsShown()) {
if (focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip))) {
return;
}
if (!m_blockFocusLost && !m_latteView->containsMouse()
&& (!m_secConfigView || (m_secConfigView && !m_secConfigView->isActive()))) {
if (!hasFocus()) {
hideConfigWindow();
}
}
@ -554,19 +569,6 @@ void PrimaryConfigView::setInAdvancedMode(bool advanced)
emit inAdvancedModeChanged();
}
void PrimaryConfigView::hideConfigWindow()
{
if (m_shellSurface) {
//!NOTE: Avoid crash in wayland environment with qt5.9
close();
} else {
hide();
}
hideCanvasWindow();
hideSecondaryWindow();
}
//!BEGIN borders
void PrimaryConfigView::updateEnabledBorders()
{

View File

@ -88,6 +88,8 @@ public:
bool inAdvancedMode() const;
void setInAdvancedMode(bool advanced);
bool hasFocus() const;
bool isReady() const;
bool showInlineProperties() const;
@ -99,8 +101,7 @@ public:
void setParentView(Latte::View *view) override;
void setOnActivities(QStringList activities);
void showPrimaryWindow();
void hidePrimaryWindow();
void showConfigWindow();
void requestActivate() override;

View File

@ -92,6 +92,8 @@ void SecondaryConfigView::initParentView(Latte::View *view)
{
SubConfigView::initParentView(view);
rootContext()->setContextProperty(QStringLiteral("primaryConfigView"), m_parent);
updateEnabledBorders();
syncGeometry();
}
@ -207,15 +209,14 @@ void SecondaryConfigView::focusOutEvent(QFocusEvent *ev)
const auto *focusWindow = qGuiApp->focusWindow();
if ((focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip)))
|| m_latteView->alternativesIsShown()) {
if (focusWindow && (focusWindow->flags().testFlag(Qt::Popup)
|| focusWindow->flags().testFlag(Qt::ToolTip))) {
return;
}
const auto parent = qobject_cast<PrimaryConfigView *>(m_parent);
if (!m_latteView->containsMouse() && parent && !parent->sticker() && !parent->isActive()) {
if (!parent->hasFocus()) {
parent->hideConfigWindow();
}
}

View File

@ -72,9 +72,10 @@ public:
QRect geometryWhenVisible() const;
void hideConfigWindow();
public slots:
Q_INVOKABLE void syncGeometry() override;
Q_INVOKABLE void hideConfigWindow();
Q_INVOKABLE void updateEffects();
signals:

View File

@ -457,9 +457,9 @@ void View::showConfigurationInterface(Plasma::Applet *applet)
if (m_primaryConfigView && c && c->isContainment() && c == this->containment()) {
if (m_primaryConfigView->isVisible()) {
m_primaryConfigView->hidePrimaryWindow();
m_primaryConfigView->hideConfigWindow();
} else {
m_primaryConfigView->showPrimaryWindow();
m_primaryConfigView->showConfigWindow();
applyActivitiesToWindows();
}

View File

@ -66,7 +66,7 @@ FocusScope {
Keys.onPressed: {
if (event.key === Qt.Key_Escape) {
viewConfig.hideConfigWindow();
primaryConfigView.hideConfigWindow();
}
}
}