Changeset View
Changeset View
Standalone View
Standalone View
main_wayland.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Line(s) | 266 | for (const QString &application: m_applicationsToStart) { | |||
---|---|---|---|---|---|
272 | p->start(application); | 272 | p->start(application); | ||
273 | } | 273 | } | ||
274 | } | 274 | } | ||
275 | } | 275 | } | ||
276 | 276 | | |||
277 | static const QString s_waylandPlugin = QStringLiteral("KWinWaylandWaylandBackend"); | 277 | static const QString s_waylandPlugin = QStringLiteral("KWinWaylandWaylandBackend"); | ||
278 | static const QString s_x11Plugin = QStringLiteral("KWinWaylandX11Backend"); | 278 | static const QString s_x11Plugin = QStringLiteral("KWinWaylandX11Backend"); | ||
279 | static const QString s_fbdevPlugin = QStringLiteral("KWinWaylandFbdevBackend"); | 279 | static const QString s_fbdevPlugin = QStringLiteral("KWinWaylandFbdevBackend"); | ||
280 | #if HAVE_DRM | | |||
281 | static const QString s_drmPlugin = QStringLiteral("KWinWaylandDrmBackend"); | 280 | static const QString s_drmPlugin = QStringLiteral("KWinWaylandDrmBackend"); | ||
282 | #endif | | |||
283 | #if HAVE_LIBHYBRIS | | |||
284 | static const QString s_hwcomposerPlugin = QStringLiteral("KWinWaylandHwcomposerBackend"); | 281 | static const QString s_hwcomposerPlugin = QStringLiteral("KWinWaylandHwcomposerBackend"); | ||
285 | #endif | | |||
286 | static const QString s_virtualPlugin = QStringLiteral("KWinWaylandVirtualBackend"); | 282 | static const QString s_virtualPlugin = QStringLiteral("KWinWaylandVirtualBackend"); | ||
287 | 283 | | |||
288 | static QString automaticBackendSelection() | | |||
289 | { | | |||
290 | if (qEnvironmentVariableIsSet("WAYLAND_DISPLAY")) { | | |||
291 | return s_waylandPlugin; | | |||
292 | } | | |||
293 | if (qEnvironmentVariableIsSet("DISPLAY")) { | | |||
294 | return s_x11Plugin; | | |||
295 | } | | |||
296 | #if HAVE_LIBHYBRIS | | |||
297 | if (qEnvironmentVariableIsSet("ANDROID_ROOT")) { | | |||
298 | return s_hwcomposerPlugin; | | |||
299 | } | | |||
300 | #endif | | |||
301 | #if HAVE_DRM | | |||
302 | return s_drmPlugin; | | |||
303 | #endif | | |||
304 | return s_fbdevPlugin; | | |||
305 | } | | |||
306 | 284 | | |||
307 | static void disablePtrace() | 285 | static void disablePtrace() | ||
308 | { | 286 | { | ||
309 | #if HAVE_PR_SET_DUMPABLE | 287 | #if HAVE_PR_SET_DUMPABLE | ||
310 | // check whether we are running under a debugger | 288 | // check whether we are running under a debugger | ||
311 | const QFileInfo parent(QStringLiteral("/proc/%1/exe").arg(getppid())); | 289 | const QFileInfo parent(QStringLiteral("/proc/%1/exe").arg(getppid())); | ||
312 | if (parent.isSymLink() && | 290 | if (parent.isSymLink() && | ||
313 | (parent.symLinkTarget().endsWith(QLatin1String("/gdb")) || | 291 | (parent.symLinkTarget().endsWith(QLatin1String("/gdb")) || | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 345 | { | |||
403 | KWin::ApplicationWayland a(argc, argv); | 381 | KWin::ApplicationWayland a(argc, argv); | ||
404 | a.setupTranslator(); | 382 | a.setupTranslator(); | ||
405 | // reset QT_QPA_PLATFORM to a sane value for any processes started from KWin | 383 | // reset QT_QPA_PLATFORM to a sane value for any processes started from KWin | ||
406 | setenv("QT_QPA_PLATFORM", "wayland", true); | 384 | setenv("QT_QPA_PLATFORM", "wayland", true); | ||
407 | 385 | | |||
408 | KWin::Application::createAboutData(); | 386 | KWin::Application::createAboutData(); | ||
409 | KQuickAddons::QtQuickSettings::init(); | 387 | KQuickAddons::QtQuickSettings::init(); | ||
410 | 388 | | |||
411 | const auto availablePlugins = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.waylandbackends")); | 389 | // load all plugins metadata | ||
390 | QVector<KPluginMetaData> availablePlugins = KPluginLoader::findPlugins(QStringLiteral("org.kde.kwin.waylandbackends")); | ||||
391 | // sort plugins descending by autoLoadPriority from JSON metadata | ||||
392 | std::sort(availablePlugins.begin(), availablePlugins.end(), | ||||
393 | [] (const KPluginMetaData &a, const KPluginMetaData &b) -> bool { | ||||
394 | int prio1 = 0, prio2 = 0; | ||||
395 | QJsonObject jsonData = a.rawData(); | ||||
396 | auto it = jsonData.find(QStringLiteral("autoLoadPriority")); | ||||
397 | if (it != jsonData.end()) { | ||||
398 | if ((*it).isDouble()) { | ||||
399 | prio1 = static_cast<int>((*it).toDouble()); | ||||
400 | } | ||||
anthonyfieroni: Just use `toInt` | |||||
401 | } | ||||
402 | jsonData = b.rawData(); | ||||
403 | it = jsonData.find(QStringLiteral("autoLoadPriority")); | ||||
404 | if (it != jsonData.end()) { | ||||
405 | if ((*it).isDouble()) { | ||||
406 | prio2 = static_cast<int>((*it).toDouble()); | ||||
407 | } | ||||
anthonyfieroni: ditto | |||||
408 | } | ||||
409 | return prio2 < prio1; | ||||
410 | }); | ||||
412 | auto hasPlugin = [&availablePlugins] (const QString &name) { | 411 | auto hasPlugin = [&availablePlugins] (const QString &name) { | ||
413 | return std::any_of(availablePlugins.begin(), availablePlugins.end(), | 412 | return std::any_of(availablePlugins.begin(), availablePlugins.end(), | ||
414 | [name] (const KPluginMetaData &plugin) { | 413 | [name] (const KPluginMetaData &plugin) { | ||
415 | return plugin.pluginId() == name; | 414 | return plugin.pluginId() == name; | ||
416 | } | 415 | } | ||
417 | ); | 416 | ); | ||
418 | }; | 417 | }; | ||
418 | | ||||
419 | const bool hasSizeOption = hasPlugin(KWin::s_x11Plugin) || hasPlugin(KWin::s_virtualPlugin); | 419 | const bool hasSizeOption = hasPlugin(KWin::s_x11Plugin) || hasPlugin(KWin::s_virtualPlugin); | ||
420 | const bool hasOutputCountOption = hasPlugin(KWin::s_x11Plugin); | 420 | const bool hasOutputCountOption = hasPlugin(KWin::s_x11Plugin); | ||
421 | const bool hasX11Option = hasPlugin(KWin::s_x11Plugin); | 421 | const bool hasX11Option = hasPlugin(KWin::s_x11Plugin); | ||
422 | const bool hasVirtualOption = hasPlugin(KWin::s_virtualPlugin); | 422 | const bool hasVirtualOption = hasPlugin(KWin::s_virtualPlugin); | ||
423 | const bool hasWaylandOption = hasPlugin(KWin::s_waylandPlugin); | 423 | const bool hasWaylandOption = hasPlugin(KWin::s_waylandPlugin); | ||
424 | const bool hasFramebufferOption = hasPlugin(KWin::s_fbdevPlugin); | 424 | const bool hasFramebufferOption = hasPlugin(KWin::s_fbdevPlugin); | ||
425 | #if HAVE_DRM | | |||
426 | const bool hasDrmOption = hasPlugin(KWin::s_drmPlugin); | 425 | const bool hasDrmOption = hasPlugin(KWin::s_drmPlugin); | ||
427 | #endif | | |||
428 | #if HAVE_LIBHYBRIS | | |||
429 | const bool hasHwcomposerOption = hasPlugin(KWin::s_hwcomposerPlugin); | 426 | const bool hasHwcomposerOption = hasPlugin(KWin::s_hwcomposerPlugin); | ||
430 | #endif | | |||
431 | 427 | | |||
432 | QCommandLineOption xwaylandOption(QStringLiteral("xwayland"), | 428 | QCommandLineOption xwaylandOption(QStringLiteral("xwayland"), | ||
433 | i18n("Start a rootless Xwayland server.")); | 429 | i18n("Start a rootless Xwayland server.")); | ||
434 | QCommandLineOption waylandSocketOption(QStringList{QStringLiteral("s"), QStringLiteral("socket")}, | 430 | QCommandLineOption waylandSocketOption(QStringList{QStringLiteral("s"), QStringLiteral("socket")}, | ||
435 | i18n("Name of the Wayland socket to listen on. If not set \"wayland-0\" is used."), | 431 | i18n("Name of the Wayland socket to listen on. If not set \"wayland-0\" is used."), | ||
436 | QStringLiteral("socket")); | 432 | QStringLiteral("socket")); | ||
437 | QCommandLineOption framebufferOption(QStringLiteral("framebuffer"), | 433 | QCommandLineOption framebufferOption(QStringLiteral("framebuffer"), | ||
438 | i18n("Render to framebuffer.")); | 434 | i18n("Render to framebuffer.")); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
485 | if (hasSizeOption) { | 481 | if (hasSizeOption) { | ||
486 | parser.addOption(widthOption); | 482 | parser.addOption(widthOption); | ||
487 | parser.addOption(heightOption); | 483 | parser.addOption(heightOption); | ||
488 | parser.addOption(scaleOption); | 484 | parser.addOption(scaleOption); | ||
489 | } | 485 | } | ||
490 | if (hasOutputCountOption) { | 486 | if (hasOutputCountOption) { | ||
491 | parser.addOption(outputCountOption); | 487 | parser.addOption(outputCountOption); | ||
492 | } | 488 | } | ||
493 | #if HAVE_LIBHYBRIS | | |||
494 | QCommandLineOption hwcomposerOption(QStringLiteral("hwcomposer"), i18n("Use libhybris hwcomposer")); | 489 | QCommandLineOption hwcomposerOption(QStringLiteral("hwcomposer"), i18n("Use libhybris hwcomposer")); | ||
495 | if (hasHwcomposerOption) { | 490 | if (hasHwcomposerOption) { | ||
496 | parser.addOption(hwcomposerOption); | 491 | parser.addOption(hwcomposerOption); | ||
497 | } | 492 | } | ||
498 | #endif | | |||
499 | QCommandLineOption libinputOption(QStringLiteral("libinput"), | 493 | QCommandLineOption libinputOption(QStringLiteral("libinput"), | ||
500 | i18n("Enable libinput support for input events processing. Note: never use in a nested session.")); | 494 | i18n("Enable libinput support for input events processing. Note: never use in a nested session.")); | ||
501 | parser.addOption(libinputOption); | 495 | parser.addOption(libinputOption); | ||
502 | #if HAVE_DRM | | |||
503 | QCommandLineOption drmOption(QStringLiteral("drm"), i18n("Render through drm node.")); | 496 | QCommandLineOption drmOption(QStringLiteral("drm"), i18n("Render through drm node.")); | ||
504 | if (hasDrmOption) { | 497 | if (hasDrmOption) { | ||
505 | parser.addOption(drmOption); | 498 | parser.addOption(drmOption); | ||
506 | } | 499 | } | ||
507 | #endif | | |||
508 | 500 | | |||
509 | QCommandLineOption inputMethodOption(QStringLiteral("inputmethod"), | 501 | QCommandLineOption inputMethodOption(QStringLiteral("inputmethod"), | ||
510 | i18n("Input method that KWin starts."), | 502 | i18n("Input method that KWin starts."), | ||
511 | QStringLiteral("path/to/imserver")); | 503 | QStringLiteral("path/to/imserver")); | ||
512 | parser.addOption(inputMethodOption); | 504 | parser.addOption(inputMethodOption); | ||
513 | 505 | | |||
514 | QCommandLineOption listBackendsOption(QStringLiteral("list-backends"), | 506 | QCommandLineOption listBackendsOption(QStringLiteral("list-backends"), | ||
515 | i18n("List all available backends and quit.")); | 507 | i18n("List all available backends and quit.")); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 536 | #endif | |||
557 | KWin::Application::setUseLibinput(parser.isSet(libinputOption)); | 549 | KWin::Application::setUseLibinput(parser.isSet(libinputOption)); | ||
558 | 550 | | |||
559 | QString pluginName; | 551 | QString pluginName; | ||
560 | QSize initialWindowSize; | 552 | QSize initialWindowSize; | ||
561 | QByteArray deviceIdentifier; | 553 | QByteArray deviceIdentifier; | ||
562 | int outputCount = 1; | 554 | int outputCount = 1; | ||
563 | qreal outputScale = 1; | 555 | qreal outputScale = 1; | ||
564 | 556 | | |||
565 | #if HAVE_DRM | | |||
566 | if (hasDrmOption && parser.isSet(drmOption)) { | | |||
567 | pluginName = KWin::s_drmPlugin; | | |||
568 | } | | |||
569 | #endif | | |||
570 | | ||||
571 | if (hasSizeOption) { | 557 | if (hasSizeOption) { | ||
572 | bool ok = false; | 558 | bool ok = false; | ||
573 | const int width = parser.value(widthOption).toInt(&ok); | 559 | const int width = parser.value(widthOption).toInt(&ok); | ||
574 | if (!ok) { | 560 | if (!ok) { | ||
575 | std::cerr << "FATAL ERROR incorrect value for width" << std::endl; | 561 | std::cerr << "FATAL ERROR incorrect value for width" << std::endl; | ||
576 | return 1; | 562 | return 1; | ||
577 | } | 563 | } | ||
578 | const int height = parser.value(heightOption).toInt(&ok); | 564 | const int height = parser.value(heightOption).toInt(&ok); | ||
Show All 14 Lines | |||||
593 | if (hasOutputCountOption) { | 579 | if (hasOutputCountOption) { | ||
594 | bool ok = false; | 580 | bool ok = false; | ||
595 | const int count = parser.value(outputCountOption).toInt(&ok); | 581 | const int count = parser.value(outputCountOption).toInt(&ok); | ||
596 | if (ok) { | 582 | if (ok) { | ||
597 | outputCount = qMax(1, count); | 583 | outputCount = qMax(1, count); | ||
598 | } | 584 | } | ||
599 | } | 585 | } | ||
600 | 586 | | |||
587 | // decide which backend plugin to load based on command-line arguments | ||||
588 | if (hasDrmOption && parser.isSet(drmOption)) { | ||||
589 | pluginName = KWin::s_drmPlugin; | ||||
590 | } | ||||
601 | if (hasX11Option && parser.isSet(x11DisplayOption)) { | 591 | if (hasX11Option && parser.isSet(x11DisplayOption)) { | ||
602 | deviceIdentifier = parser.value(x11DisplayOption).toUtf8(); | 592 | deviceIdentifier = parser.value(x11DisplayOption).toUtf8(); | ||
603 | pluginName = KWin::s_x11Plugin; | 593 | pluginName = KWin::s_x11Plugin; | ||
604 | } else if (hasWaylandOption && parser.isSet(waylandDisplayOption)) { | 594 | } else if (hasWaylandOption && parser.isSet(waylandDisplayOption)) { | ||
605 | deviceIdentifier = parser.value(waylandDisplayOption).toUtf8(); | 595 | deviceIdentifier = parser.value(waylandDisplayOption).toUtf8(); | ||
606 | pluginName = KWin::s_waylandPlugin; | 596 | pluginName = KWin::s_waylandPlugin; | ||
607 | } | 597 | } | ||
608 | 598 | | |||
609 | if (hasFramebufferOption && parser.isSet(framebufferOption)) { | 599 | if (hasFramebufferOption && parser.isSet(framebufferOption)) { | ||
610 | pluginName = KWin::s_fbdevPlugin; | 600 | pluginName = KWin::s_fbdevPlugin; | ||
611 | deviceIdentifier = parser.value(framebufferDeviceOption).toUtf8(); | 601 | deviceIdentifier = parser.value(framebufferDeviceOption).toUtf8(); | ||
612 | } | 602 | } | ||
613 | #if HAVE_LIBHYBRIS | | |||
614 | if (hasHwcomposerOption && parser.isSet(hwcomposerOption)) { | 603 | if (hasHwcomposerOption && parser.isSet(hwcomposerOption)) { | ||
615 | pluginName = KWin::s_hwcomposerPlugin; | 604 | pluginName = KWin::s_hwcomposerPlugin; | ||
616 | } | 605 | } | ||
617 | #endif | | |||
618 | if (hasVirtualOption && parser.isSet(virtualFbOption)) { | 606 | if (hasVirtualOption && parser.isSet(virtualFbOption)) { | ||
619 | pluginName = KWin::s_virtualPlugin; | 607 | pluginName = KWin::s_virtualPlugin; | ||
620 | } | 608 | } | ||
621 | 609 | | |||
622 | if (pluginName.isEmpty()) { | 610 | if (pluginName.isEmpty()) { | ||
623 | std::cerr << "No backend specified through command line argument, trying auto resolution" << std::endl; | 611 | std::cerr << "No backend specified through command line argument, " | ||
624 | pluginName = KWin::automaticBackendSelection(); | 612 | "trying auto resolution" << std::endl; | ||
613 | // plugins are sorted by priority in descending order; so, | ||||
614 | // take first one that "agrees" to load | ||||
615 | for (KPluginMetaData &plugin: availablePlugins) { | ||||
616 | KWin::Platform *backendPlugin = qobject_cast<KWin::Platform *>(plugin.instantiate()); | ||||
617 | if (backendPlugin->canLoad()) { | ||||
618 | pluginName = plugin.pluginId(); | ||||
619 | std::cerr << "Automatically chosen wayland backend:" << qPrintable(plugin.name()) << std::endl; | ||||
620 | break; | ||||
621 | } | ||||
622 | delete backendPlugin; | ||||
623 | } | ||||
625 | } | 624 | } | ||
626 | 625 | | |||
627 | auto pluginIt = std::find_if(availablePlugins.begin(), availablePlugins.end(), | 626 | auto pluginIt = std::find_if(availablePlugins.begin(), availablePlugins.end(), | ||
628 | [&pluginName] (const KPluginMetaData &plugin) { | 627 | [&pluginName] (const KPluginMetaData &plugin) { | ||
629 | return plugin.pluginId() == pluginName; | 628 | return plugin.pluginId() == pluginName; | ||
630 | } | 629 | } | ||
631 | ); | 630 | ); | ||
632 | if (pluginIt == availablePlugins.end()) { | 631 | if (pluginIt == availablePlugins.end()) { | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
Just use toInt