From 3712ecc7295b91176f51763a048a83a9c7b98d01 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 5 Apr 2014 10:11:02 +0200 Subject: QX11Info: add nextStartupId/setNextStartupId - for startup-notification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This controls what the next window to be shown will send as startup-notification message. http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt Change-Id: Ia1b5e6ba004d61ca6fdfd6683d2e22dfcd0c42fb Reviewed-by: Jędrzej Nowacki Reviewed-by: Richard J. Moore --- src/x11extras/qx11info_x11.cpp | 47 ++++++++++++++++++++++++++++++++++++ src/x11extras/qx11info_x11.h | 3 +++ tests/auto/qx11info/tst_qx11info.cpp | 29 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/src/x11extras/qx11info_x11.cpp b/src/x11extras/qx11info_x11.cpp index 2a7e495..fb70ba8 100644 --- a/src/x11extras/qx11info_x11.cpp +++ b/src/x11extras/qx11info_x11.cpp @@ -286,6 +286,53 @@ unsigned long QX11Info::getTimestamp() return static_cast(reinterpret_cast(native->nativeResourceForScreen("gettimestamp", screen))); } +/*! + Returns the startup ID that will be used for the next window to be shown by this process. + + After the next window is shown, the next startup ID will be empty. + + http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt + + \since 5.4 + \sa setNextStartupId() +*/ +QByteArray QX11Info::nextStartupId() +{ + if (!qApp) + return 0; + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return 0; + return static_cast(native->nativeResourceForIntegration("startupid")); +} + +/*! + Sets the next startup ID to \a id. + + This is the startup ID that will be used for the next window to be shown by this process. + + The startup ID of the first window comes from the environment variable DESKTOP_STARTUP_ID. + This method is useful for subsequent windows, when the request comes from another process + (e.g. via DBus). + + \since 5.4 + \sa nextStartupId() +*/ +void QX11Info::setNextStartupId(const QByteArray &id) +{ + if (!qApp) + return; + QPlatformNativeInterface *native = qApp->platformNativeInterface(); + if (!native) + return; + typedef void (*SetStartupIdFunc)(const char*); + SetStartupIdFunc func = reinterpret_cast(native->nativeResourceFunctionForIntegration("setstartupid")); + if (func) + func(id.constData()); + else + qWarning("Internal error: QPA plugin doesn't implement setStartupId"); +} + /*! Returns the default display for the application. diff --git a/src/x11extras/qx11info_x11.h b/src/x11extras/qx11info_x11.h index d5d00f3..6e07ba7 100644 --- a/src/x11extras/qx11info_x11.h +++ b/src/x11extras/qx11info_x11.h @@ -69,6 +69,9 @@ public: static unsigned long getTimestamp(); + static QByteArray nextStartupId(); + static void setNextStartupId(const QByteArray &id); + static Display *display(); static xcb_connection_t *connection(); diff --git a/tests/auto/qx11info/tst_qx11info.cpp b/tests/auto/qx11info/tst_qx11info.cpp index 602de1d..8334690 100644 --- a/tests/auto/qx11info/tst_qx11info.cpp +++ b/tests/auto/qx11info/tst_qx11info.cpp @@ -52,6 +52,7 @@ class tst_QX11Info : public QObject private slots: void staticFunctionsBeforeQApplication(); + void startupId(); void isPlatformX11(); void appTime(); }; @@ -110,6 +111,34 @@ void tst_QX11Info::staticFunctionsBeforeQApplication() QCOMPARE(appTime, 0ul); } +static const char idFromEnv[] = "startupid_TIME123456"; +void initialize() +{ + qputenv("DESKTOP_STARTUP_ID", idFromEnv); +} +Q_CONSTRUCTOR_FUNCTION(initialize) + +void tst_QX11Info::startupId() +{ + int argc = 0; + QApplication app(argc, 0); + + // This relies on the fact that no widget was shown yet, + // so please make sure this method is always the first test. + QCOMPARE(QString(QX11Info::nextStartupId()), QString(idFromEnv)); + QWidget w; + w.show(); + QVERIFY(QX11Info::nextStartupId().isEmpty()); + + QByteArray idSecondWindow = "startupid2_TIME234567"; + QX11Info::setNextStartupId(idSecondWindow); + QCOMPARE(QX11Info::nextStartupId(), idSecondWindow); + + QWidget w2; + w2.show(); + QVERIFY(QX11Info::nextStartupId().isEmpty()); +} + void tst_QX11Info::isPlatformX11() { int argc = 0; -- cgit v1.2.1