From 94827c7405a09c3de950c73cdab63ee7e45118df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 29 Jun 2015 11:59:27 +0200 Subject: [PATCH] [wayland] Introduce automatic backend selection If none of the backend specific command line options are passed, we try to autmatically determine the proper plugin. 1. if DISPLAY is set -> x11 backend 2. if WAYLAND_DISPLAY is set -> wayland backend 3. if compiled with libhybris and ANDROID_ROOT is set -> hwcomposer backend 4. if compiled with DRM -> drm backend 5. if nothing selected yet, fallback to fbdev --- main_wayland.cpp | 70 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/main_wayland.cpp b/main_wayland.cpp index a69249659d..6ecbe6afff 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -377,6 +377,35 @@ bool EventDispatcher::hasPendingEvents() return QEventDispatcherUNIX::hasPendingEvents() || QWindowSystemInterface::windowSystemEventsQueued(); } +static const QString s_waylandPlugin = QStringLiteral("KWinWaylandWaylandBackend"); +static const QString s_x11Plugin = QStringLiteral("KWinWaylandX11Backend"); +static const QString s_fbdevPlugin = QStringLiteral("KWinWaylandFbdevBackend"); +#if HAVE_DRM +static const QString s_drmPlugin = QStringLiteral("KWinWaylandDrmBackend"); +#endif +#if HAVE_LIBHYBRIS +static const QString s_hwcomposerPlugin = QStringLiteral("KWinWaylandHwcomposerBackend"); +#endif + +static QString automaticBackendSelection() +{ + if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) { + return s_waylandPlugin; + } + if (qEnvironmentVariableIsSet("DISPLAY")) { + return s_x11Plugin; + } +#if HAVE_LIBHYBRIS + if (qEnvironmentVariableIsSet("ANDROID_ROOT")) { + return s_hwcomposerPlugin; + } +#endif +#if HAVE_DRM + return s_drmPlugin; +#endif + return s_fbdevPlugin; +} + } // namespace extern "C" @@ -524,30 +553,32 @@ KWIN_EXPORT int kdemain(int argc, char * argv[]) return 1; } if (parser.isSet(drmOption)) { - pluginName = QStringLiteral("KWinWaylandDrmBackend"); + pluginName = KWin::s_drmPlugin; } #endif + + bool ok = false; + const int width = parser.value(widthOption).toInt(&ok); + if (!ok) { + std::cerr << "FATAL ERROR incorrect value for width" << std::endl; + return 1; + } + const int height = parser.value(heightOption).toInt(&ok); + if (!ok) { + std::cerr << "FATAL ERROR incorrect value for height" << std::endl; + return 1; + } + initialWindowSize = QSize(width, height); + if (parser.isSet(windowedOption)) { - bool ok = false; - const int width = parser.value(widthOption).toInt(&ok); - if (!ok) { - std::cerr << "FATAL ERROR incorrect value for width" << std::endl; - return 1; - } - const int height = parser.value(heightOption).toInt(&ok); - if (!ok) { - std::cerr << "FATAL ERROR incorrect value for height" << std::endl; - return 1; - } - initialWindowSize = QSize(width, height); if (parser.isSet(x11DisplayOption)) { deviceIdentifier = parser.value(x11DisplayOption).toUtf8(); } else if (!parser.isSet(waylandDisplayOption)) { deviceIdentifier = qgetenv("DISPLAY"); } if (!deviceIdentifier.isEmpty()) { - pluginName = QStringLiteral("KWinWaylandX11Backend"); + pluginName = KWin::s_x11Plugin; } else { if (parser.isSet(waylandDisplayOption)) { deviceIdentifier = parser.value(waylandDisplayOption).toUtf8(); @@ -555,20 +586,25 @@ KWIN_EXPORT int kdemain(int argc, char * argv[]) deviceIdentifier = qgetenv("WAYLAND_DISPLAY"); } if (!deviceIdentifier.isEmpty()) { - pluginName = QStringLiteral("KWinWaylandWaylandBackend"); + pluginName = KWin::s_waylandPlugin; } } } if (parser.isSet(framebufferOption)) { - pluginName = QStringLiteral("KWinWaylandFbdevBackend"); + pluginName = KWin::s_fbdevPlugin; deviceIdentifier = parser.value(framebufferDeviceOption).toUtf8(); } #if HAVE_LIBHYBRIS if (parser.isSet(hwcomposerOption)) { - pluginName = QStringLiteral("KWinWaylandHwcomposerBackend"); + pluginName = KWin::s_hwcomposerPlugin; } #endif + if (pluginName.isEmpty()) { + std::cerr << "No backend specified through command line argument, trying auto resolution" << std::endl; + pluginName = KWin::automaticBackendSelection(); + } + const auto pluginCandidates = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.waylandbackends"), [&pluginName] (const KPluginMetaData &plugin) { return plugin.pluginId() == pluginName;