#include #include #include #include #include #include #include "qwayland-zkde-screencast-unstable-v1.h" class ScreencastManager : public QObject, public QtWayland::zkde_screencast_unstable_v1 { Q_OBJECT public: ScreencastManager(QObject *parent = nullptr) : QObject(parent) , QtWayland::zkde_screencast_unstable_v1(5) // Version 5 is required for stream_output { if (!isInitialized()) { qCritical() << "Failed to initialize zkde_screencast_unstable_v1. Make sure KWin is running and supports this protocol."; QCoreApplication::quit(); return; } qDebug() << "zkde_screencast_unstable_v1 initialized."; // Request a screencast of the primary screen QScreen *screen = QGuiApplication::primaryScreen(); if (!screen) { qCritical() << "No primary screen found."; QCoreApplication::quit(); return; } if (auto *waylandScreen = qobject_cast(screen->nativeInterface())) { wl_output *output = waylandScreen->output(); if (!output) { qCritical() << "Failed to get native Wayland output from QWaylandScreen."; QCoreApplication::quit(); return; } // Create a stream for the output // The 'mode' parameter (last argument) can be Hidden = 1, Embedded = 2, Metadata = 4 // We'll use Metadata for now. stream_output(output, 4); // 4 for Metadata cursor mode } else { qCritical() << "Failed to get Wayland screen interface from QScreen."; QCoreApplication::quit(); return; } } protected: // Implement the generated Wayland protocol callbacks void zkde_screencast_unstable_v1_stream_created(zkde_screencast_stream_unstable_v1 *stream) override { qDebug() << "Screencast stream created!"; // Connect to the stream's signals to get the PipeWire node ID connect(static_cast(stream), &QtWayland::zkde_screencast_stream_unstable_v1::created, this, &ScreencastManager::onStreamCreated); connect(static_cast(stream), &QtWayland::zkde_screencast_stream_unstable_v1::closed, this, &ScreencastManager::onStreamClosed); connect(static_cast(stream), &QtWayland::zkde_screencast_stream_unstable_v1::failed, this, &ScreencastManager::onStreamFailed); } void zkde_screencast_unstable_v1_stream_destroyed(zkde_screencast_stream_unstable_v1 *stream) override { qDebug() << "Screencast stream destroyed."; } private slots: void onStreamCreated(quint32 node_id) { qDebug() << "PipeWire node ID:" << node_id; // Here you would typically use the node_id to connect to PipeWire and start processing frames. QCoreApplication::quit(); // For POC, quit after getting the node ID } void onStreamClosed() { qDebug() << "Screencast stream closed."; QCoreApplication::quit(); } void onStreamFailed(const QString &error) { qCritical() << "Screencast stream failed:" << error; QCoreApplication::quit(); } }; int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); qDebug() << "Starting Wayland POC..."; ScreencastManager manager; return app.exec(); } #include "wayland_poc.moc"