1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-28 19:21:50 +03:00

updates and improvements at applets glob.shortcuts

This commit is contained in:
Michail Vourlakos 2018-02-25 20:00:23 +02:00
parent 103b901125
commit 1ff161a030
7 changed files with 134 additions and 41 deletions

View File

@ -106,6 +106,12 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool dockWindo
if (!m_visibility) { if (!m_visibility) {
m_visibility = new VisibilityManager(this); 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))); connect(this->containment(), SIGNAL(statusChanged(Plasma::Types::ItemStatus)), SLOT(statusChanged(Plasma::Types::ItemStatus)));

View File

@ -220,7 +220,7 @@ void GlobalShortcuts::init()
KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + key)); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + key));
connect(action, &QAction::triggered, this, [this, i] { connect(action, &QAction::triggered, this, [this, i] {
// qDebug() << "meta action..."; // qDebug() << "meta action...";
activateTaskManagerEntry(i, static_cast<Qt::Key>(Qt::META)); activateEntry(i, static_cast<Qt::Key>(Qt::META));
}); });
} }
@ -234,7 +234,7 @@ void GlobalShortcuts::init()
action->setShortcut(QKeySequence(Qt::META + keysAboveTen[i - 10])); action->setShortcut(QKeySequence(Qt::META + keysAboveTen[i - 10]));
KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + keysAboveTen[i - 10])); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + keysAboveTen[i - 10]));
connect(action, &QAction::triggered, this, [this, i] { connect(action, &QAction::triggered, this, [this, i] {
activateTaskManagerEntry(i, static_cast<Qt::Key>(Qt::META)); activateEntry(i, static_cast<Qt::Key>(Qt::META));
}); });
} }
@ -248,7 +248,7 @@ void GlobalShortcuts::init()
KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + key)); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + key));
connect(action, &QAction::triggered, this, [this, i] { connect(action, &QAction::triggered, this, [this, i] {
// qDebug() << "meta + ctrl + action..."; // qDebug() << "meta + ctrl + action...";
activateTaskManagerEntry(i, static_cast<Qt::Key>(Qt::CTRL)); activateEntry(i, static_cast<Qt::Key>(Qt::CTRL));
}); });
} }
@ -258,7 +258,7 @@ void GlobalShortcuts::init()
action->setText(i18n("New Instance for Task Manager Entry %1", i)); action->setText(i18n("New Instance for Task Manager Entry %1", i));
KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + keysAboveTen[i - 10])); KGlobalAccel::setGlobalShortcut(action, QKeySequence(Qt::META + Qt::CTRL + keysAboveTen[i - 10]));
connect(action, &QAction::triggered, this, [this, i] { connect(action, &QAction::triggered, this, [this, i] {
activateTaskManagerEntry(i, static_cast<Qt::Key>(Qt::CTRL)); activateEntry(i, static_cast<Qt::Key>(Qt::CTRL));
}); });
} }
@ -285,11 +285,11 @@ void GlobalShortcuts::activateLauncherMenu()
//! Activate task manager entry //! Activate task manager entry
void GlobalShortcuts::activateTaskManagerEntry(int index, Qt::Key modifier) void GlobalShortcuts::activateEntry(int index, Qt::Key modifier)
{ {
m_lastInvokedAction = dynamic_cast<QAction *>(sender()); m_lastInvokedAction = dynamic_cast<QAction *>(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(); const auto &applets = c->applets();
for (auto *applet : applets) { for (auto *applet : applets) {
@ -344,6 +344,46 @@ void GlobalShortcuts::activateTaskManagerEntry(int index, Qt::Key modifier)
return false; return false;
}; };
auto activateLatteEntryOnContainment = [this](const Plasma::Containment * c, int index, Qt::Key modifier) {
if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value<QQuickItem *>()) {
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::Key>(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<const Plasma::Containment *, DockView *> *views = m_corona->layoutManager()->currentDockViews(); QHash<const Plasma::Containment *, DockView *> *views = m_corona->layoutManager()->currentDockViews();
// To avoid overly complex configuration, we'll try to get the 90% usecase to work // 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; 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 = it.value();
m_hideDock->visibility()->setBlockHiding(true); m_hideDock->visibility()->setBlockHiding(true);
m_hideDockTimer.start(); 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 // we didn't find anything on primary, try all the panels
for (auto it = views->constBegin(), end = views->constEnd(); it != end; ++it) { 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 = it.value();
m_hideDock->visibility()->setBlockHiding(true); m_hideDock->visibility()->setBlockHiding(true);
m_hideDockTimer.start(); m_hideDockTimer.start();
@ -430,41 +474,29 @@ void GlobalShortcuts::showDock()
{ {
m_lastInvokedAction = dynamic_cast<QAction *>(sender()); m_lastInvokedAction = dynamic_cast<QAction *>(sender());
auto containsLattePlasmoid = [this](const Plasma::Containment * c) { auto invokeShowNumbers = [this](const Plasma::Containment * c) {
const auto &applets = c->applets(); if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value<QQuickItem *>()) {
const auto &childItems = containmentInterface->childItems();
for (auto *applet : applets) { for (QQuickItem *item : childItems) {
KPluginMetaData meta = applet->kPackage().metadata(); 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") { // Also, "var" arguments are treated as QVariant in QMetaObject
if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value<QQuickItem *>()) { int methodIndex = metaObject->indexOfMethod("setShowAppletsNumbers(QVariant)");
const auto &childItems = containmentInterface->childItems();
if (childItems.isEmpty()) { if (methodIndex == -1) {
continue; continue;
} }
for (QQuickItem *item : childItems) { m_calledItem = item;
if (auto *metaObject = item->metaObject()) { m_numbersMethodIndex = methodIndex;
// not using QMetaObject::invokeMethod to avoid warnings when calling m_methodShowNumbers = metaObject->method(m_numbersMethodIndex);
// 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 if (m_methodShowNumbers.invoke(item, Q_ARG(QVariant, true))) {
int methodIndex = metaObject->indexOfMethod("setShowAppletsNumbers(QVariant)"); return true;
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;
}
}
} }
} }
} }
@ -482,7 +514,7 @@ void GlobalShortcuts::showDock()
continue; continue;
} }
if (containsLattePlasmoid(it.key())) { if (it.value()->latteTasksPresent() && invokeShowNumbers(it.key())) {
m_hideDock = it.value(); m_hideDock = it.value();
m_hideDock->visibility()->setBlockHiding(true); m_hideDock->visibility()->setBlockHiding(true);
m_hideDockTimer.start(); m_hideDockTimer.start();
@ -492,7 +524,7 @@ void GlobalShortcuts::showDock()
// we didn't find anything on primary, try all the panels // we didn't find anything on primary, try all the panels
for (auto it = views->constBegin(), end = views->constEnd(); it != end; ++it) { 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 = it.value();
m_hideDock->visibility()->setBlockHiding(true); m_hideDock->visibility()->setBlockHiding(true);
m_hideDockTimer.start(); m_hideDockTimer.start();
@ -671,7 +703,6 @@ void GlobalShortcuts::hideDockTimerSlot()
} }
} }
#include "moc_globalshortcuts.cpp" #include "moc_globalshortcuts.cpp"

View File

@ -49,7 +49,7 @@ private slots:
private: private:
void init(); void init();
void activateTaskManagerEntry(int index, Qt::Key modifier); void activateEntry(int index, Qt::Key modifier);
void showDock(); void showDock();
void hideDock(); void hideDock();
void showSettings(); void showSettings();

View File

@ -394,4 +394,14 @@ Item {
return counter + 1; 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;
}
} }

View File

@ -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{ Connections{

View File

@ -44,6 +44,8 @@ DragDrop.DropArea {
//// BEGIN SIGNALS //// BEGIN SIGNALS
signal clearZoomSignal(); signal clearZoomSignal();
signal separatorsUpdated(); signal separatorsUpdated();
signal signalActivateEntryAtIndex(int entryIndex);
signal signalNewInstanceForEntryAtIndex(int entryIndex);
signal updateEffectsArea(); signal updateEffectsArea();
signal updateIndexes(); signal updateIndexes();
signal updateScale(int delegateIndex, real newScale, real step); signal updateScale(int delegateIndex, real newScale, real step);
@ -1055,6 +1057,35 @@ DragDrop.DropArea {
showAppletsNumbers = showNumbers; 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){ function showTooltipLabel(taskItem, text){
titleTooltipDialog.show(taskItem, text); titleTooltipDialog.show(taskItem, text);
} }

View File

@ -1304,7 +1304,6 @@ Item {
//! this is used to bypass the internal separators if they exist //! this is used to bypass the internal separators if they exist
var confirmedIndex = parabolicManager.realTaskIndex(index - 1); var confirmedIndex = parabolicManager.realTaskIndex(index - 1);
for(var i=0; i<tasks.length; ++i){ for(var i=0; i<tasks.length; ++i){
var task = tasks[i]; var task = tasks[i];