Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activation fixes #440

Merged
merged 8 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/ipc/ipcserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
#ifndef TREMOTESF_IPCSERVER_H
#define TREMOTESF_IPCSERVER_H

#include <optional>
#include <QObject>

namespace tremotesf {
struct WindowActivationToken {
#ifdef TREMOTESF_UNIX_FREEDESKTOP
std::optional<QByteArray> x11StartupNotificationId{};
std::optional<QByteArray> waylandXdfActivationToken{};
#endif
};

class IpcServer : public QObject {
Q_OBJECT

Expand All @@ -18,12 +26,9 @@ namespace tremotesf {
inline explicit IpcServer(QObject* parent = nullptr) : QObject(parent){};

signals:
void windowActivationRequested(
const QString& torrentHash, const QByteArray& startupNotificationId, const QByteArray& xdgActivationToken
);
void torrentsAddingRequested(
const QStringList& files, const QStringList& urls, const QByteArray& startupNoficationId
);
void windowActivationRequested(const QString& torrentHash, const WindowActivationToken& token);
void
torrentsAddingRequested(const QStringList& files, const QStringList& urls, const WindowActivationToken& token);
};
}

Expand Down
20 changes: 17 additions & 3 deletions src/ipc/ipcserver_dbus_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ SPECIALIZE_FORMATTER_FOR_QDEBUG(QVariantMap)
SPECIALIZE_FORMATTER_FOR_QDEBUG(QVariantList)

namespace tremotesf {
namespace {
WindowActivationToken platformDataToWindowActivationToken(const QVariantMap& platformData) {
WindowActivationToken token{};
if (const auto startupId = platformData.value(IpcDbusService::desktopStartupIdField).toByteArray();
!startupId.isEmpty()) {
token.x11StartupNotificationId = startupId;
}
if (const auto activationToken = platformData.value(IpcDbusService::xdgActivationTokenField).toByteArray();
!activationToken.isEmpty()) {
token.waylandXdfActivationToken = activationToken;
}
return token;
}
}

IpcDbusService::IpcDbusService(IpcServerDbus* ipcServer, QObject* parent) : QObject(parent), mIpcServer(ipcServer) {
new OrgFreedesktopApplicationAdaptor(this);

Expand All @@ -39,8 +54,7 @@ namespace tremotesf {
logInfo("Window activation requested, platform_data = {}", platform_data);
emit mIpcServer->windowActivationRequested(
platform_data.value(torrentHashField).toString(),
platform_data.value(desktopStartupIdField).toByteArray(),
platform_data.value(xdgActivationTokenField).toByteArray()
platformDataToWindowActivationToken(platform_data)
);
}

Expand All @@ -57,7 +71,7 @@ namespace tremotesf {
}
}
}
emit mIpcServer->torrentsAddingRequested(files, urls, platform_data.value(desktopStartupIdField).toByteArray());
emit mIpcServer->torrentsAddingRequested(files, urls, platformDataToWindowActivationToken(platform_data));
}

void IpcDbusService::ActivateAction(
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipcserver_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace tremotesf {
const QByteArray message(socket->readAll());
if (message.size() == 1 && message.front() == activateWindowMessage) {
logInfo("IpcServerSocket: window activation requested");
emit windowActivationRequested({}, {}, {});
emit windowActivationRequested({}, {});
} else {
QCborParserError error{};
const auto cbor = QCborValue::fromCbor(message, &error);
Expand Down
2 changes: 1 addition & 1 deletion src/startup/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(int argc, char** argv) {
const SaveWindowStateDispatcher saveStateDispatcher{};

MainWindow window(std::move(args.files), std::move(args.urls));
window.showMinimized(args.minimized);
window.initialShow(args.minimized);

if (signalHandler.isExitRequested()) {
return EXIT_SUCCESS;
Expand Down
Loading
Loading