From 64a40429a48712e988e5b29157550b90f3ad45b5 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sat, 22 Sep 2018 20:21:57 +0300 Subject: [PATCH] option/define who will be used at global shortcuts --add an option in Tweaks page in order for the user to define which dock/panel will have the highest priority for global shortcuts activation. This option can be used is per layout basis. Each layout can have its own high priority dock/panel for Latte unified shortcuts. BUG: 398914 --- app/dock/dockview.cpp | 40 +++++++++++++++++-- app/dock/dockview.h | 9 ++++- app/globalshortcuts.cpp | 16 +++++++- app/layout.h | 4 ++ .../contents/configuration/TweaksConfig.qml | 14 ++++++- 5 files changed, 76 insertions(+), 7 deletions(-) diff --git a/app/dock/dockview.cpp b/app/dock/dockview.cpp index ae6e47385..de6f023f2 100644 --- a/app/dock/dockview.cpp +++ b/app/dock/dockview.cpp @@ -213,8 +213,10 @@ void DockView::init() connect(this, &DockView::maxLengthChanged, this, &DockView::syncGeometry); connect(this, &DockView::offsetChanged, this, &DockView::syncGeometry); connect(this, &DockView::alignmentChanged, this, &DockView::updateEnabledBorders); + connect(this, &DockView::dockWinBehaviorChanged, this, &DockView::saveConfig); connect(this, &DockView::onPrimaryChanged, this, &DockView::saveConfig); + connect(this, &DockView::isPreferredForShortcutsChanged, this, &DockView::saveConfig); connect(this, &DockView::locationChanged, this, [&]() { updateFormFactor(); @@ -1151,6 +1153,32 @@ void DockView::setInEditMode(bool edit) emit inEditModeChanged(); } +bool DockView::isPreferredForShortcuts() const +{ + return m_isPreferredForShortcuts; +} + +void DockView::setIsPreferredForShortcuts(bool preferred) +{ + if (m_isPreferredForShortcuts == preferred) { + return; + } + + m_isPreferredForShortcuts = preferred; + + emit isPreferredForShortcutsChanged(); + + if (m_isPreferredForShortcuts && m_managedLayout) { + emit m_managedLayout->preferredViewForShortcutsChanged(this); + } +} + +void DockView::preferredViewForShortcutsChangedSlot(DockView *view) +{ + if (view != this) { + setIsPreferredForShortcuts(false); + } +} bool DockView::onPrimary() const { @@ -1445,12 +1473,14 @@ void DockView::setManagedLayout(Layout *layout) emit activitiesChanged(); } }); + + connectionsManagedLayout[0] = connect(m_managedLayout, &Layout::preferredViewForShortcutsChanged, this, &DockView::preferredViewForShortcutsChangedSlot); } DockCorona *dockCorona = qobject_cast(this->corona()); if (dockCorona->layoutManager()->memoryUsage() == Dock::MultipleLayouts) { - connectionsManagedLayout[0] = connect(dockCorona->activitiesConsumer(), &KActivities::Consumer::runningActivitiesChanged, this, [&]() { + connectionsManagedLayout[1] = connect(dockCorona->activitiesConsumer(), &KActivities::Consumer::runningActivitiesChanged, this, [&]() { if (m_managedLayout && m_visibility) { qDebug() << "DOCK VIEW FROM LAYOUT (runningActivitiesChanged) ::: " << m_managedLayout->name() << " - activities: " << m_managedLayout->appliedActivities(); @@ -1459,14 +1489,14 @@ void DockView::setManagedLayout(Layout *layout) } }); - connectionsManagedLayout[1] = connect(m_managedLayout, &Layout::activitiesChanged, this, [&]() { + connectionsManagedLayout[2] = connect(m_managedLayout, &Layout::activitiesChanged, this, [&]() { if (m_managedLayout) { applyActivitiesToWindows(); emit activitiesChanged(); } }); - connectionsManagedLayout[2] = connect(dockCorona->layoutManager(), &LayoutManager::layoutsChanged, this, [&]() { + connectionsManagedLayout[3] = connect(dockCorona->layoutManager(), &LayoutManager::layoutsChanged, this, [&]() { if (m_managedLayout) { applyActivitiesToWindows(); emit activitiesChanged(); @@ -1475,7 +1505,7 @@ void DockView::setManagedLayout(Layout *layout) //!IMPORTANT!!! ::: This fixes a bug when closing an Activity all docks from all Activities are //! disappearing! With this they reappear!!! - connectionsManagedLayout[3] = connect(this, &QWindow::visibleChanged, this, [&]() { + connectionsManagedLayout[4] = connect(this, &QWindow::visibleChanged, this, [&]() { if (!isVisible() && m_managedLayout) { QTimer::singleShot(100, [this]() { if (m_managedLayout && containment() && !containment()->destroyed()) { @@ -1934,6 +1964,7 @@ void DockView::saveConfig() auto config = this->containment()->config(); config.writeEntry("onPrimary", onPrimary()); config.writeEntry("dockWindowBehavior", dockWinBehavior()); + config.writeEntry("isPreferredForShortcuts", isPreferredForShortcuts()); config.sync(); } @@ -1945,6 +1976,7 @@ void DockView::restoreConfig() auto config = this->containment()->config(); m_onPrimary = config.readEntry("onPrimary", true); m_dockWinBehavior = config.readEntry("dockWindowBehavior", true); + m_isPreferredForShortcuts = config.readEntry("isPreferredForShortcuts", false); //! Send changed signals at the end in order to be sure that saveConfig //! wont rewrite default/invalid values diff --git a/app/dock/dockview.h b/app/dock/dockview.h index dca586606..a6c6cf82c 100644 --- a/app/dock/dockview.h +++ b/app/dock/dockview.h @@ -73,6 +73,7 @@ class DockView : public PlasmaQuick::ContainmentView //! Because Latte uses animations, changing to edit mode it may be different than //! when the isUserConfiguring changes value Q_PROPERTY(bool inEditMode READ inEditMode WRITE setInEditMode NOTIFY inEditModeChanged) + Q_PROPERTY(bool isPreferredForShortcuts READ isPreferredForShortcuts WRITE setIsPreferredForShortcuts NOTIFY isPreferredForShortcutsChanged) Q_PROPERTY(bool themeHasShadow READ themeHasShadow NOTIFY themeHasShadowChanged) Q_PROPERTY(bool onPrimary READ onPrimary WRITE setOnPrimary NOTIFY onPrimaryChanged) @@ -151,6 +152,9 @@ public: bool inEditMode() const; void setInEditMode(bool edit); + bool isPreferredForShortcuts() const; + void setIsPreferredForShortcuts(bool preferred); + bool themeHasShadow() const; float maxLength() const; @@ -286,6 +290,7 @@ signals: void widthChanged(); void heightChanged(); void inEditModeChanged(); + void isPreferredForShortcutsChanged(); void localGeometryChanged(); void managedLayoutChanged(); void maxLengthChanged(); @@ -308,6 +313,7 @@ signals: private slots: void availableScreenRectChanged(); void hideWindowsForSlidingOut(); + void preferredViewForShortcutsChangedSlot(DockView *view); void statusChanged(Plasma::Types::ItemStatus); void screenChanged(QScreen *screen); void updateEffects(); @@ -339,6 +345,7 @@ private: bool m_forceDrawCenteredBorders{false}; bool m_inDelete{false}; bool m_inEditMode{false}; + bool m_isPreferredForShortcuts{false}; bool m_onPrimary{true}; int m_dockTransparency{100}; int m_fontPixelSize{ -1}; @@ -370,7 +377,7 @@ private: QTimer m_validateGeometryTimer; //! Connections to release and bound for the managed layout - std::array connectionsManagedLayout; + std::array connectionsManagedLayout; //!used at sliding out/in animation QString m_moveToLayout; diff --git a/app/globalshortcuts.cpp b/app/globalshortcuts.cpp index d52e8daad..f118865d7 100644 --- a/app/globalshortcuts.cpp +++ b/app/globalshortcuts.cpp @@ -802,10 +802,24 @@ QList GlobalShortcuts::sortedViewsList(QHashisPreferredForShortcuts()) { + highestPriorityView = docks[i]; + docks.removeAt(i); + break; + } + } + + if (highestPriorityView) { + docks.prepend(highestPriorityView); + } + qDebug() << " -------- sorted -----"; for (int i = 0; i < docks.count(); ++i) { - qDebug() << i << ". " << docks[i]->screen()->name() << " - " << docks[i]->location(); + qDebug() << i << ". " << docks[i]->isPreferredForShortcuts() << " - " << docks[i]->screen()->name() << " - " << docks[i]->location(); } return docks; diff --git a/app/layout.h b/app/layout.h index 506ff35cc..8fc0f5edf 100644 --- a/app/layout.h +++ b/app/layout.h @@ -164,6 +164,10 @@ signals: void showInMenuChanged(); void textColorChanged(); + //! used from DockView(s) in order to exist only one each time that has the highest priority + //! to use the global shortcuts activations + void preferredViewForShortcutsChanged(DockView *view); + private slots: void loadConfig(); void saveConfig(); diff --git a/shell/package/contents/configuration/TweaksConfig.qml b/shell/package/contents/configuration/TweaksConfig.qml index 32ccf3bbc..d22ba0b6a 100644 --- a/shell/package/contents/configuration/TweaksConfig.qml +++ b/shell/package/contents/configuration/TweaksConfig.qml @@ -166,7 +166,7 @@ PlasmaComponents.Page { text: i18n("Activate KWin edge after hiding") checked: dock.visibility.enableKWinEdges - onCheckedChanged: { + onClicked: { dock.visibility.enableKWinEdges = checked; } } @@ -194,6 +194,18 @@ PlasmaComponents.Page { } } + PlasmaComponents.CheckBox { + Layout.leftMargin: units.smallSpacing * 2 + text: i18n("Prefer for global shortcuts activation") + checked: dock.isPreferredForShortcuts + + tooltip: i18n("Enable highest priority for global shortcuts activation") + + onClicked: { + dock.isPreferredForShortcuts = checked + } + } + PlasmaComponents.CheckBox { Layout.leftMargin: units.smallSpacing * 2 text: i18n("Behave as a normal dock window")