diff --git a/app/dock/dockview.cpp b/app/dock/dockview.cpp index ec6feabfa..dfcc8b598 100644 --- a/app/dock/dockview.cpp +++ b/app/dock/dockview.cpp @@ -106,6 +106,12 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool dockWindo if (!m_visibility) { m_visibility = new VisibilityManager(this); + + connect(m_visibility, &VisibilityManager::isHiddenChanged, this, [&]() { + if (m_visibility->isHidden()) { + deactivateApplets(); + } + }); } connect(this->containment(), SIGNAL(statusChanged(Plasma::Types::ItemStatus)), SLOT(statusChanged(Plasma::Types::ItemStatus))); diff --git a/app/globalshortcuts.cpp b/app/globalshortcuts.cpp index 1ace57016..215511de7 100644 --- a/app/globalshortcuts.cpp +++ b/app/globalshortcuts.cpp @@ -220,7 +220,7 @@ void GlobalShortcuts::init() KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + key)); connect(action, &QAction::triggered, this, [this, i] { // qDebug() << "meta action..."; - activateTaskManagerEntry(i, static_cast(Qt::META)); + activateEntry(i, static_cast(Qt::META)); }); } @@ -234,7 +234,7 @@ void GlobalShortcuts::init() action->setShortcut(QKeySequence(Qt::META + keysAboveTen[i - 10])); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + keysAboveTen[i - 10])); connect(action, &QAction::triggered, this, [this, i] { - activateTaskManagerEntry(i, static_cast(Qt::META)); + activateEntry(i, static_cast(Qt::META)); }); } @@ -248,7 +248,7 @@ void GlobalShortcuts::init() KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + key)); connect(action, &QAction::triggered, this, [this, i] { // qDebug() << "meta + ctrl + action..."; - activateTaskManagerEntry(i, static_cast(Qt::CTRL)); + activateEntry(i, static_cast(Qt::CTRL)); }); } @@ -258,7 +258,7 @@ void GlobalShortcuts::init() action->setText(i18n("New Instance for Task Manager Entry %1", i)); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + keysAboveTen[i - 10])); connect(action, &QAction::triggered, this, [this, i] { - activateTaskManagerEntry(i, static_cast(Qt::CTRL)); + activateEntry(i, static_cast(Qt::CTRL)); }); } @@ -285,11 +285,11 @@ void GlobalShortcuts::activateLauncherMenu() //! Activate task manager entry -void GlobalShortcuts::activateTaskManagerEntry(int index, Qt::Key modifier) +void GlobalShortcuts::activateEntry(int index, Qt::Key modifier) { m_lastInvokedAction = dynamic_cast(sender()); - auto activateTaskManagerEntryOnContainment = [this](const Plasma::Containment * c, int index, Qt::Key modifier) { + auto activatePlasmaTaskManagerEntryOnContainment = [this](const Plasma::Containment * c, int index, Qt::Key modifier) { const auto &applets = c->applets(); for (auto *applet : applets) { @@ -344,6 +344,46 @@ void GlobalShortcuts::activateTaskManagerEntry(int index, Qt::Key modifier) return false; }; + + auto activateLatteEntryOnContainment = [this](const Plasma::Containment * c, int index, Qt::Key modifier) { + if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value()) { + const auto &childItems = containmentInterface->childItems(); + + for (QQuickItem *item : childItems) { + if (auto *metaObject = item->metaObject()) { + // not using QMetaObject::invokeMethod to avoid warnings when calling + // this on applets that don't have it or other child items since this + // is pretty much trial and error. + + // Also, "var" arguments are treated as QVariant in QMetaObject + int methodIndex = modifier == static_cast(Qt::META) ? + metaObject->indexOfMethod("activateEntryAtIndex(QVariant)") : + metaObject->indexOfMethod("newInstanceForEntryAtIndex(QVariant)"); + + int methodIndex2 = metaObject->indexOfMethod("setShowAppletsNumbers(QVariant)"); + + if (methodIndex == -1 || (methodIndex2 == -1)) { + continue; + } + + m_calledItem = item; + m_numbersMethodIndex = methodIndex2; + m_methodShowNumbers = metaObject->method(m_numbersMethodIndex); + + QMetaMethod method = metaObject->method(methodIndex); + + if (method.invoke(item, Q_ARG(QVariant, index))) { + m_methodShowNumbers.invoke(item, Q_ARG(QVariant, true)); + + return true; + } + } + } + } + + return false; + }; + QHash *views = m_corona->layoutManager()->currentDockViews(); // To avoid overly complex configuration, we'll try to get the 90% usecase to work @@ -353,7 +393,9 @@ void GlobalShortcuts::activateTaskManagerEntry(int index, Qt::Key modifier) continue; } - if (activateTaskManagerEntryOnContainment(it.key(), index, modifier)) { + if ((it.value()->latteTasksPresent() && activateLatteEntryOnContainment(it.key(), index, modifier)) + || (!it.value()->latteTasksPresent() && it.value()->tasksPresent() && + activatePlasmaTaskManagerEntryOnContainment(it.key(), index, modifier))) { m_hideDock = it.value(); m_hideDock->visibility()->setBlockHiding(true); m_hideDockTimer.start(); @@ -363,7 +405,9 @@ void GlobalShortcuts::activateTaskManagerEntry(int index, Qt::Key modifier) // we didn't find anything on primary, try all the panels for (auto it = views->constBegin(), end = views->constEnd(); it != end; ++it) { - if (activateTaskManagerEntryOnContainment(it.key(), index, modifier)) { + if ((it.value()->latteTasksPresent() && activateLatteEntryOnContainment(it.key(), index, modifier)) + || (!it.value()->latteTasksPresent() && it.value()->tasksPresent() && + activatePlasmaTaskManagerEntryOnContainment(it.key(), index, modifier))) { m_hideDock = it.value(); m_hideDock->visibility()->setBlockHiding(true); m_hideDockTimer.start(); @@ -430,41 +474,29 @@ void GlobalShortcuts::showDock() { m_lastInvokedAction = dynamic_cast(sender()); - auto containsLattePlasmoid = [this](const Plasma::Containment * c) { - const auto &applets = c->applets(); + auto invokeShowNumbers = [this](const Plasma::Containment * c) { + if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value()) { + const auto &childItems = containmentInterface->childItems(); - for (auto *applet : applets) { - KPluginMetaData meta = applet->kPackage().metadata(); + for (QQuickItem *item : childItems) { + if (auto *metaObject = item->metaObject()) { + // not using QMetaObject::invokeMethod to avoid warnings when calling + // this on applets that don't have it or other child items since this + // is pretty much trial and error. - if (meta.pluginId() == "org.kde.latte.plasmoid") { - if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value()) { - const auto &childItems = containmentInterface->childItems(); + // Also, "var" arguments are treated as QVariant in QMetaObject + int methodIndex = metaObject->indexOfMethod("setShowAppletsNumbers(QVariant)"); - if (childItems.isEmpty()) { + if (methodIndex == -1) { continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - // not using QMetaObject::invokeMethod to avoid warnings when calling - // this on applets that don't have it or other child items since this - // is pretty much trial and error. - - // Also, "var" arguments are treated as QVariant in QMetaObject - int methodIndex = metaObject->indexOfMethod("setShowAppletsNumbers(QVariant)"); + m_calledItem = item; + m_numbersMethodIndex = methodIndex; + m_methodShowNumbers = metaObject->method(m_numbersMethodIndex); - if (methodIndex == -1) { - continue; - } - - m_calledItem = item; - m_numbersMethodIndex = methodIndex; - m_methodShowNumbers = metaObject->method(m_numbersMethodIndex); - - if (m_methodShowNumbers.invoke(item, Q_ARG(QVariant, true))) { - return true; - } - } + if (m_methodShowNumbers.invoke(item, Q_ARG(QVariant, true))) { + return true; } } } @@ -482,7 +514,7 @@ void GlobalShortcuts::showDock() continue; } - if (containsLattePlasmoid(it.key())) { + if (it.value()->latteTasksPresent() && invokeShowNumbers(it.key())) { m_hideDock = it.value(); m_hideDock->visibility()->setBlockHiding(true); m_hideDockTimer.start(); @@ -492,7 +524,7 @@ void GlobalShortcuts::showDock() // we didn't find anything on primary, try all the panels for (auto it = views->constBegin(), end = views->constEnd(); it != end; ++it) { - if (containsLattePlasmoid(it.key())) { + if (it.value()->latteTasksPresent() && invokeShowNumbers(it.key())) { m_hideDock = it.value(); m_hideDock->visibility()->setBlockHiding(true); m_hideDockTimer.start(); @@ -671,7 +703,6 @@ void GlobalShortcuts::hideDockTimerSlot() } - } #include "moc_globalshortcuts.cpp" diff --git a/app/globalshortcuts.h b/app/globalshortcuts.h index 1038ef761..ea04d2b9a 100644 --- a/app/globalshortcuts.h +++ b/app/globalshortcuts.h @@ -49,7 +49,7 @@ private slots: private: void init(); - void activateTaskManagerEntry(int index, Qt::Key modifier); + void activateEntry(int index, Qt::Key modifier); void showDock(); void hideDock(); void showSettings(); diff --git a/containment/package/contents/ui/ParabolicManager.qml b/containment/package/contents/ui/ParabolicManager.qml index 838905014..4ac181aea 100644 --- a/containment/package/contents/ui/ParabolicManager.qml +++ b/containment/package/contents/ui/ParabolicManager.qml @@ -394,4 +394,14 @@ Item { return counter + 1; } + + function pseudoIndexBelongsToLatteApplet(index) { + if (root.latteApplet) { + var lastTaskIndex = root.latteApplet.tasksNumbersBase + root.latteApplet.parabolicManager.countRealTasks; + return (index>root.latteApplet.tasksNumbersBase && index<=lastTaskIndex); + } + + return false; + } + } diff --git a/containment/package/contents/ui/applet/AppletItem.qml b/containment/package/contents/ui/applet/AppletItem.qml index 91e2d09f8..a33369a5f 100644 --- a/containment/package/contents/ui/applet/AppletItem.qml +++ b/containment/package/contents/ui/applet/AppletItem.qml @@ -414,6 +414,22 @@ Item { } } } + + onSignalActivateEntryAtIndex: { + if (parabolicManager.pseudoIndexBelongsToLatteApplet(entryIndex) && container.isLattePlasmoid) { + latteApplet.activateTaskAtIndex(entryIndex - latteApplet.tasksNumbersBase); + } else if (entryIndex === parabolicManager.pseudoAppletIndex(container.index)) { + dock.toggleAppletExpanded(applet.id); + } + } + + onSignalNewInstanceForEntryAtIndex: { + if (parabolicManager.pseudoIndexBelongsToLatteApplet(entryIndex) && container.isLattePlasmoid) { + latteApplet.newInstanceForTaskAtIndex(entryIndex - latteApplet.tasksNumbersBase); + } else if (entryIndex === parabolicManager.pseudoAppletIndex(container.index)) { + dock.toggleAppletExpanded(applet.id); + } + } } Connections{ diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index bf492e1a1..96fd67f5d 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -44,6 +44,8 @@ DragDrop.DropArea { //// BEGIN SIGNALS signal clearZoomSignal(); signal separatorsUpdated(); + signal signalActivateEntryAtIndex(int entryIndex); + signal signalNewInstanceForEntryAtIndex(int entryIndex); signal updateEffectsArea(); signal updateIndexes(); signal updateScale(int delegateIndex, real newScale, real step); @@ -1055,6 +1057,35 @@ DragDrop.DropArea { showAppletsNumbers = showNumbers; } + // This is called by dockcorona in response to a Meta+number shortcut. + function activateEntryAtIndex(index) { + if (typeof index !== "number") { + return; + } + + if (latteApplet) { + var base = parabolicManager.pseudoAppletIndex(latteAppletPos); + latteApplet.setTasksNumbersBase(base - 1); + } + + signalActivateEntryAtIndex(index); + } + + // This is called by dockcorona in response to a Meta+Alt+number shortcut. + function newInstanceForEntryAtIndex(index) { + if (typeof index !== "number") { + return; + } + + if (latteApplet) { + var base = parabolicManager.pseudoAppletIndex(latteAppletPos); + latteApplet.setTasksNumbersBase(base - 1); + } + + signalNewInstanceForEntryAtIndex(index); + } + + function showTooltipLabel(taskItem, text){ titleTooltipDialog.show(taskItem, text); } diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index 2022fb2cb..8600bdd09 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -1304,7 +1304,6 @@ Item { //! this is used to bypass the internal separators if they exist var confirmedIndex = parabolicManager.realTaskIndex(index - 1); - for(var i=0; i