diff options
author | Jørgen Lind <jorgen.lind@digia.com> | 2013-04-25 15:15:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-26 14:18:16 +0200 |
commit | 7288625c52749f566570a7e7ef047faa8171b18c (patch) | |
tree | c4c3d0e2808bc868a6440060f7db661417268d0f /src/plugins/platforms/xcb/qxcbintegration.cpp | |
parent | f8e2a8469f91ac1a7daf73c8ed9c24195e5b5a56 (diff) |
Moving logic from Qt4 for grabbing the X server
Basically you don't want to grab the X server while your debugging.
Also added an environment variable which lets you force to not grab
the X server
Change-Id: Iba03f11c8f486ce71c55fac7716bffcb7cc8cb98
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbintegration.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbintegration.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index f0cabea43d..dd1466d23c 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -91,8 +91,34 @@ #endif #endif +#include <QtCore/QFileInfo> + QT_BEGIN_NAMESPACE +#if defined(QT_DEBUG) && defined(Q_OS_LINUX) +// Find out if our parent process is gdb by looking at the 'exe' symlink under /proc,. +// or, for older Linuxes, read out 'cmdline'. +static bool runningUnderDebugger() +{ + const QString parentProc = QLatin1String("/proc/") + QString::number(getppid()); + const QFileInfo parentProcExe(parentProc + QLatin1String("/exe")); + if (parentProcExe.isSymLink()) + return parentProcExe.symLinkTarget().endsWith(QLatin1String("/gdb")); + QFile f(parentProc + QLatin1String("/cmdline")); + if (!f.open(QIODevice::ReadOnly)) + return false; + QByteArray s; + char c; + while (f.getChar(&c) && c) { + if (c == '/') + s.clear(); + else + s += c; + } + return s == "gdb"; +} +#endif + QXcbIntegration::QXcbIntegration(const QStringList ¶meters) : m_eventDispatcher(createUnixEventDispatcher()) , m_services(new QGenericUnixServices) @@ -104,7 +130,15 @@ QXcbIntegration::QXcbIntegration(const QStringList ¶meters) #endif m_nativeInterface.reset(new QXcbNativeInterface); - m_connections << new QXcbConnection(m_nativeInterface.data()); + bool canGrab = true; + #if defined(QT_DEBUG) && defined(Q_OS_LINUX) + canGrab = !runningUnderDebugger(); + #endif + static bool canNotGrabEnv = qgetenv("QT_XCB_NO_GRAB_SERVER").length(); + if (canNotGrabEnv) + canGrab = false; + + m_connections << new QXcbConnection(m_nativeInterface.data(), canGrab); for (int i = 0; i < parameters.size() - 1; i += 2) { #ifdef Q_XCB_DEBUG |