Commit 48592f67 authored by Christoph Cullmann's avatar Christoph Cullmann

Kate - Modified the DBus behaviour or re-use the existing instances

Patch by Joao Carreira <jfmcarreira@gmail.com>

REVIEW: 127283
parent 8a358f5b
......@@ -106,6 +106,12 @@ bool KateAppAdaptor::activateSession(QString session)
return m_app->sessionManager()->activateSession(session);
}
int KateAppAdaptor::desktopNumber()
{
KWindowInfo appInfo(m_app->activeKateMainWindow()->winId(), NET::WMDesktop);
return appInfo.desktop();
}
QString KateAppAdaptor::activeSession()
{
return m_app->sessionManager()->activeSession()->name();
......
......@@ -93,6 +93,8 @@ public Q_SLOTS:
*/
bool activateSession(QString session);
int desktopNumber();
/**
* activate this kate instance
*/
......
......@@ -25,6 +25,7 @@
#include <KAboutData>
#include <KLocalizedString>
#include <KWindowSystem>
#include <KStartupInfo>
#include <kdbusservice.h>
......@@ -273,14 +274,43 @@ int main(int argc, char **argv)
}
}
// prefer the Kate instance running on the current virtual desktop
bool foundRunningService = false;
if ((!force_new) && (serviceName.isEmpty())) {
if (kateServices.count() > 0) {
serviceName = kateServices[0];
const int desktopnumber = KWindowSystem::currentDesktop();
int sessionDesktopNumber;
for (int s = 0; s < kateServices.count(); s++) {
serviceName = kateServices[s];
if (!serviceName.isEmpty()) {
QDBusReply<bool> there = sessionBusInterface->isServiceRegistered(serviceName);
if (there.isValid() && there.value()) {
sessionDesktopNumber = -1;
// query instance current desktop
QDBusMessage m = QDBusMessage::createMethodCall(serviceName,
QStringLiteral("/MainApplication"), QStringLiteral("org.kde.Kate.Application"), QStringLiteral("desktopNumber"));
QDBusMessage res = QDBusConnection::sessionBus().call(m);
QList<QVariant> answer = res.arguments();
if (answer.size() == 1) {
sessionDesktopNumber = answer.at(0).toInt();
if (sessionDesktopNumber == desktopnumber) {
// stop searching. a candidate instance in the current desktop has been found
foundRunningService = true;
break;
}
}
}
}
serviceName.clear();
}
}
//check again if service is still running
bool foundRunningService = false;
foundRunningService = false;
if (!serviceName.isEmpty()) {
QDBusReply<bool> there = sessionBusInterface->isServiceRegistered(serviceName);
foundRunningService = there.isValid() && there.value();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment