kde-plasma-6/kwin/fix-screencast-pipewire.patch

129 lines
5.0 KiB
Diff

diff --git a/src/plugins/screencast/pipewirecore.cpp b/src/plugins/screencast/pipewirecore.cpp
index 077854c65e..eabf89a852 100644
--- a/src/plugins/screencast/pipewirecore.cpp
+++ b/src/plugins/screencast/pipewirecore.cpp
@@ -94,6 +94,18 @@ bool PipeWireCore::init()
return true;
}
+std::shared_ptr<PipeWireCore> PipeWireCore::self()
+{
+ static std::weak_ptr<PipeWireCore> global;
+ auto ret = global.lock();
+ if (!ret) {
+ ret = std::make_shared<PipeWireCore>();
+ ret->init();
+ global = ret;
+ }
+ return ret;
+}
+
} // namespace KWin
#include "moc_pipewirecore.cpp"
diff --git a/src/plugins/screencast/screencastmanager.cpp b/src/plugins/screencast/screencastmanager.cpp
index 87c84e93f3..d0a2d6552d 100644
--- a/src/plugins/screencast/screencastmanager.cpp
+++ b/src/plugins/screencast/screencastmanager.cpp
@@ -10,7 +10,6 @@
#include "core/output.h"
#include "core/outputbackend.h"
#include "outputscreencastsource.h"
-#include "pipewirecore.h"
#include "regionscreencastsource.h"
#include "screencaststream.h"
#include "wayland/display.h"
@@ -27,9 +26,7 @@ namespace KWin
ScreencastManager::ScreencastManager()
: m_screencast(new ScreencastV1Interface(waylandServer()->display(), this))
- , m_core(new PipeWireCore)
{
- m_core->init();
connect(m_screencast, &ScreencastV1Interface::windowScreencastRequested, this, &ScreencastManager::streamWindow);
connect(m_screencast, &ScreencastV1Interface::outputScreencastRequested, this, &ScreencastManager::streamWaylandOutput);
connect(m_screencast, &ScreencastV1Interface::virtualOutputScreencastRequested, this, &ScreencastManager::streamVirtualOutput);
@@ -46,7 +43,7 @@ void ScreencastManager::streamWindow(ScreencastStreamV1Interface *waylandStream,
return;
}
- auto stream = new ScreenCastStream(new WindowScreenCastSource(window), m_core, this);
+ auto stream = new ScreenCastStream(new WindowScreenCastSource(window), this);
stream->setObjectName(window->desktopFileName());
stream->setCursorMode(mode, 1, window->clientGeometry());
@@ -88,7 +85,7 @@ void ScreencastManager::streamOutput(ScreencastStreamV1Interface *waylandStream,
return;
}
- auto stream = new ScreenCastStream(new OutputScreenCastSource(streamOutput), m_core, this);
+ auto stream = new ScreenCastStream(new OutputScreenCastSource(streamOutput), this);
stream->setObjectName(streamOutput->name());
stream->setCursorMode(mode, streamOutput->scale(), streamOutput->geometry());
@@ -112,7 +109,7 @@ void ScreencastManager::streamRegion(ScreencastStreamV1Interface *waylandStream,
}
auto source = new RegionScreenCastSource(geometry, scale);
- auto stream = new ScreenCastStream(source, m_core, this);
+ auto stream = new ScreenCastStream(source, this);
stream->setObjectName(rectToString(geometry));
stream->setCursorMode(mode, scale, geometry);
diff --git a/src/plugins/screencast/screencastmanager.h b/src/plugins/screencast/screencastmanager.h
index 059e64b545..c4829c0bd0 100644
--- a/src/plugins/screencast/screencastmanager.h
+++ b/src/plugins/screencast/screencastmanager.h
@@ -16,7 +16,6 @@ namespace KWin
{
class Output;
class ScreenCastStream;
-class PipeWireCore;
class ScreencastManager : public Plugin
{
@@ -47,7 +46,6 @@ private:
void integrateStreams(ScreencastStreamV1Interface *waylandStream, ScreenCastStream *stream);
ScreencastV1Interface *m_screencast;
- std::shared_ptr<PipeWireCore> m_core;
};
} // namespace KWin
diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp
index 43d5044c17..183389704b 100644
--- a/src/plugins/screencast/screencaststream.cpp
+++ b/src/plugins/screencast/screencaststream.cpp
@@ -321,9 +321,8 @@ void ScreenCastStream::onStreamRenegotiateFormat(uint64_t)
pw_stream_update_params(m_pwStream, params.data(), params.count());
}
-ScreenCastStream::ScreenCastStream(ScreenCastSource *source, std::shared_ptr<PipeWireCore> pwCore, QObject *parent)
+ScreenCastStream::ScreenCastStream(ScreenCastSource *source, QObject *parent)
: QObject(parent)
- , m_pwCore(pwCore)
, m_source(source)
, m_resolution(source->textureSize())
{
@@ -364,6 +363,7 @@ ScreenCastStream::~ScreenCastStream()
bool ScreenCastStream::init()
{
+ m_pwCore = PipeWireCore::self();
if (!m_pwCore->m_error.isEmpty()) {
m_error = m_pwCore->m_error;
return false;
diff --git a/src/plugins/screencast/screencaststream.h b/src/plugins/screencast/screencaststream.h
index 5abf2dd0bb..9afe32e080 100644
--- a/src/plugins/screencast/screencaststream.h
+++ b/src/plugins/screencast/screencaststream.h
@@ -48,7 +48,7 @@ class KWIN_EXPORT ScreenCastStream : public QObject
{
Q_OBJECT
public:
- explicit ScreenCastStream(ScreenCastSource *source, std::shared_ptr<PipeWireCore> pwCore, QObject *parent);
+ explicit ScreenCastStream(ScreenCastSource *source, QObject *parent);
~ScreenCastStream();
bool init();