diff --git a/app/view/containmentinterface.cpp b/app/view/containmentinterface.cpp index 4239183c6..a4c492279 100644 --- a/app/view/containmentinterface.cpp +++ b/app/view/containmentinterface.cpp @@ -71,9 +71,9 @@ ContainmentInterface::~ContainmentInterface() { } -void ContainmentInterface::identifyMainItem() +void ContainmentInterface::identifyShortcutsHost() { - if (m_mainItem) { + if (m_shortcutsHost) { return; } @@ -82,9 +82,13 @@ void ContainmentInterface::identifyMainItem() for (QQuickItem *item : childItems) { if (item->objectName() == "containmentViewLayout" ) { - m_mainItem = item; - identifyMethods(); - return; + for (QQuickItem *subitem : item->childItems()) { + if (subitem->objectName() == "PositionShortcutsAbilityHost") { + m_shortcutsHost = subitem; + identifyMethods(); + return; + } + } } } } @@ -92,15 +96,15 @@ void ContainmentInterface::identifyMainItem() void ContainmentInterface::identifyMethods() { - int aeIndex = m_mainItem->metaObject()->indexOfMethod("activateEntryAtIndex(QVariant)"); - int niIndex = m_mainItem->metaObject()->indexOfMethod("newInstanceForEntryAtIndex(QVariant)"); - int sbIndex = m_mainItem->metaObject()->indexOfMethod("setShowAppletShortcutBadges(QVariant,QVariant,QVariant,QVariant)"); - int afiIndex = m_mainItem->metaObject()->indexOfMethod("appletIdForIndex(QVariant)"); + int aeIndex = m_shortcutsHost->metaObject()->indexOfMethod("activateEntryAtIndex(QVariant)"); + int niIndex = m_shortcutsHost->metaObject()->indexOfMethod("newInstanceForEntryAtIndex(QVariant)"); + int sbIndex = m_shortcutsHost->metaObject()->indexOfMethod("setShowAppletShortcutBadges(QVariant,QVariant,QVariant,QVariant)"); + int afiIndex = m_shortcutsHost->metaObject()->indexOfMethod("appletIdForIndex(QVariant)"); - m_activateEntryMethod = m_mainItem->metaObject()->method(aeIndex); - m_appletIdForIndexMethod = m_mainItem->metaObject()->method(afiIndex); - m_newInstanceMethod = m_mainItem->metaObject()->method(niIndex); - m_showShortcutsMethod = m_mainItem->metaObject()->method(sbIndex); + m_activateEntryMethod = m_shortcutsHost->metaObject()->method(aeIndex); + m_appletIdForIndexMethod = m_shortcutsHost->metaObject()->method(afiIndex); + m_newInstanceMethod = m_shortcutsHost->metaObject()->method(niIndex); + m_showShortcutsMethod = m_shortcutsHost->metaObject()->method(sbIndex); } bool ContainmentInterface::applicationLauncherHasGlobalShortcut() const @@ -149,7 +153,7 @@ bool ContainmentInterface::containsApplicationLauncher() const bool ContainmentInterface::isCapableToShowShortcutBadges() { - identifyMainItem(); + identifyShortcutsHost(); if (!hasLatteTasks() && hasPlasmaTasks()) { return false; @@ -322,35 +326,35 @@ bool ContainmentInterface::newInstanceForPlasmaTask(const int index) bool ContainmentInterface::activateEntry(const int index) { - identifyMainItem(); + identifyShortcutsHost(); if (!m_activateEntryMethod.isValid()) { return false; } - return m_activateEntryMethod.invoke(m_mainItem, Q_ARG(QVariant, index)); + return m_activateEntryMethod.invoke(m_shortcutsHost, Q_ARG(QVariant, index)); } bool ContainmentInterface::newInstanceForEntry(const int index) { - identifyMainItem(); + identifyShortcutsHost(); if (!m_newInstanceMethod.isValid()) { return false; } - return m_newInstanceMethod.invoke(m_mainItem, Q_ARG(QVariant, index)); + return m_newInstanceMethod.invoke(m_shortcutsHost, Q_ARG(QVariant, index)); } bool ContainmentInterface::hideShortcutBadges() { - identifyMainItem(); + identifyShortcutsHost(); if (!m_showShortcutsMethod.isValid()) { return false; } - return m_showShortcutsMethod.invoke(m_mainItem, Q_ARG(QVariant, false), Q_ARG(QVariant, false), Q_ARG(QVariant, false), Q_ARG(QVariant, -1)); + return m_showShortcutsMethod.invoke(m_shortcutsHost, Q_ARG(QVariant, false), Q_ARG(QVariant, false), Q_ARG(QVariant, false), Q_ARG(QVariant, -1)); } bool ContainmentInterface::showOnlyMeta() @@ -364,7 +368,7 @@ bool ContainmentInterface::showOnlyMeta() bool ContainmentInterface::showShortcutBadges(const bool showLatteShortcuts, const bool showMeta) { - identifyMainItem(); + identifyShortcutsHost(); if (!m_showShortcutsMethod.isValid() || !isCapableToShowShortcutBadges()) { return false; @@ -372,12 +376,12 @@ bool ContainmentInterface::showShortcutBadges(const bool showLatteShortcuts, con int appLauncherId = m_corona->universalSettings()->kwin_metaForwardedToLatte() && showMeta ? applicationLauncherId() : -1; - return m_showShortcutsMethod.invoke(m_mainItem, Q_ARG(QVariant, showLatteShortcuts), Q_ARG(QVariant, true), Q_ARG(QVariant, showMeta), Q_ARG(QVariant, appLauncherId)); + return m_showShortcutsMethod.invoke(m_shortcutsHost, Q_ARG(QVariant, showLatteShortcuts), Q_ARG(QVariant, true), Q_ARG(QVariant, showMeta), Q_ARG(QVariant, appLauncherId)); } int ContainmentInterface::appletIdForVisualIndex(const int index) { - identifyMainItem(); + identifyShortcutsHost(); if (!m_appletIdForIndexMethod.isValid()) { return false; @@ -385,7 +389,7 @@ int ContainmentInterface::appletIdForVisualIndex(const int index) QVariant appletId{-1}; - m_appletIdForIndexMethod.invoke(m_mainItem, Q_RETURN_ARG(QVariant, appletId), Q_ARG(QVariant, index)); + m_appletIdForIndexMethod.invoke(m_shortcutsHost, Q_RETURN_ARG(QVariant, appletId), Q_ARG(QVariant, index)); return appletId.toInt(); } diff --git a/app/view/containmentinterface.h b/app/view/containmentinterface.h index 74402734a..19628eb02 100644 --- a/app/view/containmentinterface.h +++ b/app/view/containmentinterface.h @@ -104,7 +104,7 @@ signals: void plasmaTasksModelChanged(); private slots: - void identifyMainItem(); + void identifyShortcutsHost(); void identifyMethods(); void updateAppletsTracking(); @@ -130,7 +130,7 @@ private: QPointer m_corona; QPointer m_view; - QPointer m_mainItem; + QPointer m_shortcutsHost; //! startup timer to initialize //! applets tracking diff --git a/containment/package/contents/ui/abilities/Indexer.qml b/containment/package/contents/ui/abilities/Indexer.qml index 1b32804f8..5accf64c2 100644 --- a/containment/package/contents/ui/abilities/Indexer.qml +++ b/containment/package/contents/ui/abilities/Indexer.qml @@ -23,6 +23,8 @@ import org.kde.plasma.plasmoid 2.0 import "./privates" as Ability Ability.IndexerPrivate { + objectName: "IndexerAbilityHost" + //! do not update during dragging/moving applets inConfigureAppletsMode updateIsBlocked: (root.dragOverlay && root.dragOverlay.pressed) || layouter.appletsInParentChange @@ -43,15 +45,34 @@ Ability.IndexerPrivate { return false; } - function visibleIndex(actualIndex) { - if ((separators.indexOf(actualIndex) >= 0) || (hidden.indexOf(actualIndex) >= 0)) { - return -1; + function appletIdForVisibleIndex(itemVisibleIndex) { + var sLayout = layouts.startLayout; + for (var i=0; i= 0) || (hidden.indexOf(actualIndex) >= 0)) { + return -1; + } + + var visibleItems = visibleItemsBeforeCount(layouts.startLayout, actualIndex) + + visibleItemsBeforeCount(layouts.mainLayout, actualIndex) + + visibleItemsBeforeCount(layouts.endLayout, actualIndex); + + return visibleItems; + } + + function visibleIndexBelongsAtApplet(applet, itemVisibleIndex) { + if (itemVisibleIndex<0 || !applet) { + return false; + } + + var vIndexBase = visibleIndex(applet.index); + + if (vIndexBase === itemVisibleIndex) { + return true; + } else if (applet.communicator + && applet.communicator.indexerIsSupported + && applet.communicator.bridge + && applet.communicator.bridge.indexer) { + if (itemVisibleIndex >= vIndexBase + && itemVisibleIndex< (vIndexBase + appletItem.communicator.bridge.indexer.client.visibleItemsCount)) { + return true; + } + } + + return false; + } } diff --git a/containment/package/contents/ui/abilities/privates/PositionShortcutsPrivate.qml b/containment/package/contents/ui/abilities/privates/PositionShortcutsPrivate.qml index 9d0e1089e..e25a0a408 100644 --- a/containment/package/contents/ui/abilities/privates/PositionShortcutsPrivate.qml +++ b/containment/package/contents/ui/abilities/privates/PositionShortcutsPrivate.qml @@ -20,96 +20,64 @@ import QtQuick 2.7 Item { - objectName: "PositionShortcuts" + id: _shortcutsprivate + property Item layouts: null + property bool updateIsBlocked: false - property bool unifiedGlobalShortcuts: true + readonly property bool unifiedGlobalShortcuts: appletIdStealingPositionShortcuts === -1 - property bool showLatteShortcutBadges: false + property bool showPositionShortcutBadges: false property bool showAppletShortcutBadges: false property bool showMetaBadge: false property int applicationLauncherId: -1 + property int appletIdStealingPositionShortcuts: -1 + signal sglActivateEntryAtIndex(int entryIndex); signal sglNewInstanceForEntryAtIndex(int entryIndex); - //! this is called from globalshortcuts c++ side - function setShowAppletShortcutBadges(showLatteShortcuts, showShortcuts, showMeta, applicationLauncher){ - if (latteApplet) { - var base = unifiedGlobalShortcuts ? parabolicManager.pseudoAppletIndex(latteAppletPos) : 1; - latteApplet.setTasksBaseIndex(base - 1); - latteApplet.setShowTaskShortcutBadges(showLatteShortcuts); - } - - showLatteShortcutBadges = showLatteShortcuts; - showAppletShortcutBadges = showShortcuts; - showMetaBadge = showMeta; - applicationLauncherId = applicationLauncher; - - if (latteApplet) { - latteApplet.parabolicManager.updateTasksEdgesIndexes(); - } - } - - //! this is called from Latte::View::ContainmentInterface - function activateEntryAtIndex(index) { - if (typeof index !== "number") { - return; - } - - if (latteApplet) { - var base = unifiedGlobalShortcuts ? parabolicManager.pseudoAppletIndex(latteAppletPos) : 1; - latteApplet.setTasksBaseIndex(base - 1); - latteApplet.parabolicManager.updateTasksEdgesIndexes(); - } - - signalActivateEntryAtIndex(index); - } - - //! this is called from Latte::View::ContainmentInterface - function newInstanceForEntryAtIndex(index) { - if (typeof index !== "number") { - return; - } - - if (latteApplet) { - var base = unifiedGlobalShortcuts ? parabolicManager.pseudoAppletIndex(latteAppletPos) : 1; - latteApplet.setTasksBaseIndex(base - 1); - latteApplet.parabolicManager.updateTasksEdgesIndexes(); - } - - signalNewInstanceForEntryAtIndex(index); - } - - //! this is called from Latte::View::ContainmentInterface - function appletIdForIndex(index) { - if (!root.unifiedGlobalShortcuts || parabolicManager.pseudoIndexBelongsToLatteApplet(index)) { - return -1; - } - - for (var i=0; i=0 + && appletItem.communicator + && appletItem.communicator.onPositionShortcutsAreSupported + && appletItem.communicator.bridge.shortcuts.client.isStealingGlobalPositionShortcuts) { + return appletItem.index; + } } - } - - for (var j=0; j=0 + && appletItem.communicator + && appletItem.communicator.onPositionShortcutsAreSupported + && appletItem.communicator.bridge.shortcuts.client.isStealingGlobalPositionShortcuts) { + return appletItem.index; + } } - } - - for (var k=0; j=0 + && appletItem.communicator + && appletItem.communicator.onPositionShortcutsAreSupported + && appletItem.communicator.bridge.shortcuts.client.isStealingGlobalPositionShortcuts) { + return appletItem.index; + } } - } - return -1; + return -1; + } } } diff --git a/containment/package/contents/ui/applet/AppletItem.qml b/containment/package/contents/ui/applet/AppletItem.qml index ee2d9d55e..ef329b531 100644 --- a/containment/package/contents/ui/applet/AppletItem.qml +++ b/containment/package/contents/ui/applet/AppletItem.qml @@ -288,6 +288,7 @@ Item { property Item layouter: null property Item metrics: null property Item parabolic: null + property Item shortcuts: null property bool containsMouse: appletMouseArea.containsMouse || (isLattePlasmoid && latteApplet.containsMouse) property bool pressed: viewSignalsConnector.pressed || clickedAnimation.running @@ -612,20 +613,20 @@ Item { //! Connections Connections{ - target: root + target: appletItem.shortcuts - onSignalActivateEntryAtIndex: { + onSglActivateEntryAtIndex: { if (parabolicManager.pseudoIndexBelongsToLatteApplet(entryIndex) && appletItem.isLattePlasmoid) { latteApplet.activateTaskAtIndex(entryIndex - latteApplet.tasksBaseIndex); - } else if (root.unifiedGlobalShortcuts && refersEntryIndex(entryIndex)) { + } else if (shortcuts.unifiedGlobalShortcuts && refersEntryIndex(entryIndex)) { latteView.extendedInterface.toggleAppletExpanded(applet.id); } } - onSignalNewInstanceForEntryAtIndex: { + onSglNewInstanceForEntryAtIndex: { if (parabolicManager.pseudoIndexBelongsToLatteApplet(entryIndex) && appletItem.isLattePlasmoid) { latteApplet.newInstanceForTaskAtIndex(entryIndex - latteApplet.tasksBaseIndex); - } else if (root.unifiedGlobalShortcuts && refersEntryIndex(entryIndex)) { + } else if (shortcuts.unifiedGlobalShortcuts && refersEntryIndex(entryIndex)) { latteView.extendedInterface.toggleAppletExpanded(applet.id); } } diff --git a/containment/package/contents/ui/applet/ShortcutBadge.qml b/containment/package/contents/ui/applet/ShortcutBadge.qml index 8fde91dd1..674f50cda 100644 --- a/containment/package/contents/ui/applet/ShortcutBadge.qml +++ b/containment/package/contents/ui/applet/ShortcutBadge.qml @@ -26,9 +26,9 @@ Loader{ id: appletNumberLoader active: appletItem.canShowAppletNumberBadge && - (root.showLatteShortcutBadges - || root.showAppletShortcutBadges - || root.showMetaBadge && applet.id===applicationLauncherId) + (appletItem.shortcuts.showPositionShortcutBadges + || appletItem.shortcuts.showAppletShortcutBadges + || appletItem.shortcuts.showMetaBadge && applet.id===appletItem.shortcuts.applicationLauncherId) asynchronous: true visible: badgeString!=="" @@ -37,7 +37,7 @@ Loader{ property string badgeString: "" onActiveChanged: { - if (active && root.showLatteShortcutBadges && root.unifiedGlobalShortcuts) { + if (active && appletItem.shortcuts.showPositionShortcutBadges && appletItem.shortcuts.unifiedGlobalShortcuts) { fixedIndex = appletItem.indexer.visibleIndex(index); } else { fixedIndex = -1; @@ -45,7 +45,7 @@ Loader{ } Component.onCompleted: { - if (active && root.showLatteShortcutBadges && root.unifiedGlobalShortcuts) { + if (active && appletItem.shortcuts.showPositionShortcutBadges && appletItem.shortcuts.unifiedGlobalShortcuts) { fixedIndex = appletItem.indexer.visibleIndex(index); } else { fixedIndex = -1; @@ -55,13 +55,13 @@ Loader{ Binding{ target: appletNumberLoader property:"badgeString" - when: root.showMetaBadge || root.showAppletShortcutBadges + when: appletItem.shortcuts.showMetaBadge || appletItem.shortcuts.showAppletShortcutBadges value: { - if (root.showMetaBadge && applet && applet.id === applicationLauncherId) { + if (appletItem.shortcuts.showMetaBadge && applet && applet.id === appletItem.shortcuts.applicationLauncherId) { return '\u2318'; } - if (root.showAppletShortcutBadges) { + if (appletItem.shortcuts.showAppletShortcutBadges) { var plasmaShortcut = applet ? shortcutsEngine.appletShortcutBadge(applet.id) : ""; if (plasmaShortcut !== "") { diff --git a/containment/package/contents/ui/applet/communicator/Engine.qml b/containment/package/contents/ui/applet/communicator/Engine.qml index 3c42609f7..dec60327e 100644 --- a/containment/package/contents/ui/applet/communicator/Engine.qml +++ b/containment/package/contents/ui/applet/communicator/Engine.qml @@ -59,6 +59,7 @@ Item{ //! BEGIN OF ABILITIES SUPPORT readonly property bool indexerIsSupported: bridge && bridge.indexer.client + readonly property bool onPositionShortcutsAreSupported: bridge && bridge.shortcuts.client readonly property bool parabolicEffectIsSupported: bridge && bridge.parabolic.client readonly property Item bridge: bridgeLoader.active ? bridgeLoader.item : null diff --git a/containment/package/contents/ui/applet/communicator/LatteBridge.qml b/containment/package/contents/ui/applet/communicator/LatteBridge.qml index 5c5f79b9a..7ed467a60 100644 --- a/containment/package/contents/ui/applet/communicator/LatteBridge.qml +++ b/containment/package/contents/ui/applet/communicator/LatteBridge.qml @@ -132,6 +132,11 @@ Item{ appletIndex: index } + readonly property AbilityBridge.PositionShortcuts shortcuts: AbilityBridge.PositionShortcuts { + host: appletItem.shortcuts + appletIndex: index + } + Connections { target: root onBroadcastedToApplet: { diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index 314cb0235..3d9ceec97 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -1294,6 +1294,7 @@ Item { layouter: _layouter metrics: _metrics parabolic: _parabolic + shortcuts: _shortcuts } } @@ -1542,6 +1543,11 @@ Item { view: latteView } + Ability.PositionShortcuts { + id: _shortcuts + layouts: layoutsContainer + } + LatteApp.Interfaces { id: _interfaces plasmoidInterface: plasmoid diff --git a/declarativeimports/abilities/bridge/PositionShortcuts.qml b/declarativeimports/abilities/bridge/PositionShortcuts.qml new file mode 100644 index 000000000..144899a86 --- /dev/null +++ b/declarativeimports/abilities/bridge/PositionShortcuts.qml @@ -0,0 +1,28 @@ +/* +* Copyright 2020 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* Latte-Dock is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +import QtQuick 2.0 + +Item { + id: shortcutsBridge + property int appletIndex: -1 + + property Item host: null + property Item client: null +} diff --git a/declarativeimports/abilities/bridge/qmldir b/declarativeimports/abilities/bridge/qmldir index 5ba776a73..7fc30c3f7 100644 --- a/declarativeimports/abilities/bridge/qmldir +++ b/declarativeimports/abilities/bridge/qmldir @@ -2,3 +2,4 @@ module org.kde.latte.abilities.applets Indexer 0.1 Indexer.qml ParabolicEffect 0.1 ParabolicEffect.qml +PositionShortcuts 0.1 PositionShortcuts.qml