From fc0272f3c44ffa16364a2f1505b0858ed1c3816b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 2 Oct 2015 09:31:47 +0200 Subject: [PATCH] [wayland] Add a --list-backends command line arg for listing available backends Distributions do package each backend plugin in a dedicated package, which means just because KWin got compiled with a specific backend, doesn't mean it is also available at runtime. In order to better support this reality this change introduces a list-backends command line option. Each of the plugins got the json metadata extended by the KPlugin syntax, so that we have a name and description to print. As we already locate all plugins anyway, the additional findPlugins for the selected backend is changed to search the list of all plugin meta data. --- backends/drm/drm.json | 5 ++++ backends/fbdev/fbdev.json | 5 ++++ backends/hwcomposer/hwcomposer.json | 5 ++++ backends/wayland/wayland.json | 5 ++++ backends/x11/x11.json | 5 ++++ main_wayland.cpp | 41 ++++++++++++++++++----------- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/backends/drm/drm.json b/backends/drm/drm.json index 404bba5384..843cff6e05 100644 --- a/backends/drm/drm.json +++ b/backends/drm/drm.json @@ -1,3 +1,8 @@ { + "KPlugin": { + "Id": "KWinWaylandDrmBackend", + "Name": "drm", + "Description": "Render through drm node." + }, "input": false } diff --git a/backends/fbdev/fbdev.json b/backends/fbdev/fbdev.json index 404bba5384..0bcb7bc990 100644 --- a/backends/fbdev/fbdev.json +++ b/backends/fbdev/fbdev.json @@ -1,3 +1,8 @@ { + "KPlugin": { + "Id": "KWinWaylandFbdevBackend", + "Name": "framebuffer", + "Description": "Render to framebuffer." + }, "input": false } diff --git a/backends/hwcomposer/hwcomposer.json b/backends/hwcomposer/hwcomposer.json index 1551bf5de1..e15108c9e7 100644 --- a/backends/hwcomposer/hwcomposer.json +++ b/backends/hwcomposer/hwcomposer.json @@ -1,3 +1,8 @@ { + "KPlugin": { + "Id": "KWinWaylandHwcomposerBackend", + "Name": "hwcomposer", + "Description": "Render through hwcomposer through libhybris." + }, "input": true } diff --git a/backends/wayland/wayland.json b/backends/wayland/wayland.json index 1551bf5de1..95e707b4c9 100644 --- a/backends/wayland/wayland.json +++ b/backends/wayland/wayland.json @@ -1,3 +1,8 @@ { + "KPlugin": { + "Id": "KWinWaylandWaylandBackend", + "Name": "wayland", + "Description": "Render to a nested window on running Wayland compositor." + }, "input": true } diff --git a/backends/x11/x11.json b/backends/x11/x11.json index 1551bf5de1..0d5ef5b598 100644 --- a/backends/x11/x11.json +++ b/backends/x11/x11.json @@ -1,3 +1,8 @@ { + "KPlugin": { + "Id": "KWinWaylandX11Backend", + "Name": "x11", + "Description": "Render to a nested window on X11 windowing system." + }, "input": true } diff --git a/main_wayland.cpp b/main_wayland.cpp index de2e5d2799..36cc34864b 100644 --- a/main_wayland.cpp +++ b/main_wayland.cpp @@ -51,6 +51,7 @@ along with this program. If not, see . #endif // HAVE_UNISTD_H #include +#include namespace KWin { @@ -382,6 +383,8 @@ int main(int argc, char * argv[]) KWin::Application::createAboutData(); + const auto availablePlugins = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.waylandbackends")); + QCommandLineOption xwaylandOption(QStringLiteral("xwayland"), i18n("Start a rootless Xwayland server.")); QCommandLineOption waylandSocketOption(QStringList{QStringLiteral("s"), QStringLiteral("socket")}, @@ -440,6 +443,10 @@ int main(int argc, char * argv[]) QStringLiteral("path/to/imserver")); parser.addOption(inputMethodOption); + QCommandLineOption listBackendsOption(QStringLiteral("list-backends"), + i18n("List all available backends and quit.")); + parser.addOption(listBackendsOption); + parser.addPositionalArgument(QStringLiteral("applications"), i18n("Applications to start once Wayland and Xwayland server are started"), QStringLiteral("[/path/to/application...]")); @@ -447,6 +454,13 @@ int main(int argc, char * argv[]) parser.process(a); a.processCommandLine(&parser); + if (parser.isSet(listBackendsOption)) { + for (const auto &plugin: availablePlugins) { + std::cout << std::setw(40) << std::left << qPrintable(plugin.name()) << qPrintable(plugin.description()) << std::endl; + } + return 0; + } + #if HAVE_INPUT KWin::Application::setUseLibinput(parser.isSet(libinputOption)); #endif @@ -516,12 +530,12 @@ int main(int argc, char * argv[]) pluginName = KWin::automaticBackendSelection(); } - const auto pluginCandidates = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.waylandbackends"), + auto pluginIt = std::find_if(availablePlugins.begin(), availablePlugins.end(), [&pluginName] (const KPluginMetaData &plugin) { return plugin.pluginId() == pluginName; } ); - if (pluginCandidates.isEmpty()) { + if (pluginIt == availablePlugins.end()) { std::cerr << "FATAL ERROR: could not find a backend" << std::endl; return 1; } @@ -530,23 +544,20 @@ int main(int argc, char * argv[]) KWin::WaylandServer *server = KWin::WaylandServer::create(&a); server->init(parser.value(waylandSocketOption).toUtf8()); - for (const auto &candidate: pluginCandidates) { - if (qobject_cast(candidate.instantiate())) { + if (qobject_cast((*pluginIt).instantiate())) { #if HAVE_INPUT - // check whether it needs libinput - const QJsonObject &metaData = candidate.rawData(); - auto it = metaData.find(QStringLiteral("input")); - if (it != metaData.constEnd()) { - if ((*it).isBool()) { - if (!(*it).toBool()) { - std::cerr << "Backend does not support input, enforcing libinput support" << std::endl; - KWin::Application::setUseLibinput(true); - } + // check whether it needs libinput + const QJsonObject &metaData = (*pluginIt).rawData(); + auto it = metaData.find(QStringLiteral("input")); + if (it != metaData.constEnd()) { + if ((*it).isBool()) { + if (!(*it).toBool()) { + std::cerr << "Backend does not support input, enforcing libinput support" << std::endl; + KWin::Application::setUseLibinput(true); } } -#endif - break; } +#endif } if (!server->backend()) { std::cerr << "FATAL ERROR: could not instantiate a backend" << std::endl;