diff --git a/resources/qml/voip/ScreenShare.qml b/resources/qml/voip/ScreenShare.qml
index 80ea75d2..1a82a5ce 100644
--- a/resources/qml/voip/ScreenShare.qml
+++ b/resources/qml/voip/ScreenShare.qml
@@ -14,10 +14,6 @@ Popup {
anchors.centerIn: parent;
Component.onCompleted: {
- if (CallManager.screenShareX11Available)
- CallManager.setScreenShareType(ScreenShareType.X11);
- else
- CallManager.setScreenShareType(ScreenShareType.XDP);
frameRateCombo.currentIndex = frameRateCombo.find(Settings.screenShareFrameRate);
}
Component.onDestruction: {
@@ -47,29 +43,13 @@ Popup {
color: Nheko.colors.windowText
}
- RadioButton {
- id: screenshare_X11
- text: qsTr("X11");
- visible: CallManager.screenShareX11Available
- checked: CallManager.screenShareX11Available
- onToggled: {
- if (screenshare_X11.checked)
- CallManager.setScreenShareType(ScreenShareType.X11);
- else
- CallManager.setScreenShareType(ScreenShareType.XDP);
- }
- }
- RadioButton {
- id: screenshare_XDP
- text: qsTr("xdg-desktop-portal");
- checked: !CallManager.screenShareX11Available
- onToggled: {
- if (screenshare_XDP.checked)
- CallManager.setScreenShareType(ScreenShareType.XDP);
- else
- CallManager.setScreenShareType(ScreenShareType.X11);
- }
- }
+ ComboBox {
+ id: screenshareType
+
+ Layout.fillWidth: true
+ model: CallManager.screenShareTypeList()
+ onCurrentIndexChanged: CallManager.setScreenShareType(currentIndex);
+ }
}
RowLayout {
@@ -84,7 +64,7 @@ Popup {
}
ComboBox {
- visible: screenshare_X11.checked
+ visible: CallManager.screenShareType == ScreenShareType.X11
id: windowCombo
Layout.fillWidth: true
@@ -92,7 +72,7 @@ Popup {
}
Button {
- visible: screenshare_XDP.checked
+ visible: CallManager.screenShareType == ScreenShareType.XDP
highlighted: !CallManager.screenShareReady
text: qsTr("Request screencast")
onClicked: {
diff --git a/src/voip/CallManager.cpp b/src/voip/CallManager.cpp
index 4471a0c2..e7bd45e4 100644
--- a/src/voip/CallManager.cpp
+++ b/src/voip/CallManager.cpp
@@ -68,12 +68,23 @@ CallManager::CallManager(QObject *parent)
qRegisterMetaType<mtx::events::voip::CallCandidates::Candidate>();
qRegisterMetaType<mtx::responses::TurnServer>();
- if (screenShareX11Available()) {
- screenShareType_ = ScreenShareType::X11;
- } else {
+#ifdef GSTREAMER_AVAILABLE
+ std::string errorMessage;
+ if (session_.havePlugins(true, true, ScreenShareType::XDP, &errorMessage)) {
+ screenShareTypes_.push_back(ScreenShareType::XDP);
screenShareType_ = ScreenShareType::XDP;
}
+ if (std::getenv("DISPLAY")) {
+ screenShareTypes_.push_back(ScreenShareType::X11);
+ if (QGuiApplication::platformName() != QStringLiteral("wayland")) {
+ // Selected by default
+ screenShareType_ = ScreenShareType::X11;
+ std::swap(screenShareTypes_[0], screenShareTypes_[1]);
+ }
+ }
+#endif
+
connect(
&session_,
&WebRTCSession::offerCreated,
@@ -208,13 +219,6 @@ CallManager::sendInvite(const QString &roomid, CallType callType, unsigned int w
auto roomInfo = cache::singleRoomInfo(roomid.toStdString());
std::string errorMessage;
- if (!session_.havePlugins(callType != CallType::VOICE,
- callType == CallType::SCREEN,
- screenShareType_,
- &errorMessage)) {
- emit ChatPage::instance()->showNotification(QString::fromStdString(errorMessage));
- return;
- }
callType_ = callType;
roomid_ = roomid;
@@ -745,16 +749,6 @@ CallManager::callsSupported()
#endif
}
-bool
-CallManager::screenShareX11Available()
-{
-#ifdef GSTREAMER_AVAILABLE
- return std::getenv("DISPLAY");
-#else
- return false;
-#endif
-}
-
QStringList
CallManager::devices(bool isVideo) const
{
@@ -863,9 +857,29 @@ CallManager::screenShareReady() const
}
QStringList
+CallManager::screenShareTypeList()
+{
+ QStringList ret;
+ ret.reserve(2);
+ for (ScreenShareType type : screenShareTypes_) {
+ switch (type) {
+ case ScreenShareType::X11:
+ ret.append(tr("X11"));
+ break;
+ case ScreenShareType::XDP:
+ ret.append(tr("Stream from xdg-desktop-portal"));
+ break;
+ }
+ }
+
+ return ret;
+}
+
+QStringList
CallManager::windowList()
{
- if (!screenShareX11Available()) {
+ if (!(std::find(screenShareTypes_.begin(), screenShareTypes_.end(), ScreenShareType::X11) !=
+ screenShareTypes_.end())) {
return {};
}
@@ -998,7 +1012,7 @@ CallManager::previewWindow(unsigned int index) const
}
if (screenShareType_ == ScreenShareType::X11 &&
- (!screenShareX11Available() || windows_.empty() || index >= windows_.size())) {
+ (windows_.empty() || index >= windows_.size())) {
nhlog::ui()->error("X11 screencast not available");
return;
}
@@ -1085,19 +1099,20 @@ CallManager::setupScreenShareXDP()
#ifdef GSTREAMER_AVAILABLE
ScreenCastPortal &sc_portal = ScreenCastPortal::instance();
sc_portal.init();
- screenShareType_ = ScreenShareType::XDP;
#endif
}
void
-CallManager::setScreenShareType(webrtc::ScreenShareType screenShareType)
+CallManager::setScreenShareType(unsigned int index)
{
#ifdef GSTREAMER_AVAILABLE
closeScreenShare();
- screenShareType_ = screenShareType;
+ if (index >= screenShareTypes_.size())
+ nhlog::ui()->error("WebRTC: Screen share type index out of range");
+ screenShareType_ = screenShareTypes_[index];
emit screenShareChanged();
#else
- (void)screenShareType;
+ (void)index;
#endif
}
diff --git a/src/voip/CallManager.h b/src/voip/CallManager.h
index 5d7ebda9..bbc7a903 100644
--- a/src/voip/CallManager.h
+++ b/src/voip/CallManager.h
@@ -44,7 +44,6 @@ class CallManager final : public QObject
Q_PROPERTY(QStringList mics READ mics NOTIFY devicesChanged)
Q_PROPERTY(QStringList cameras READ cameras NOTIFY devicesChanged)
Q_PROPERTY(bool callsSupported READ callsSupported CONSTANT)
- Q_PROPERTY(bool screenShareX11Available READ screenShareX11Available CONSTANT)
Q_PROPERTY(bool screenShareReady READ screenShareReady NOTIFY screenShareChanged)
public:
@@ -68,7 +67,6 @@ public:
bool screenShareReady() const;
static bool callsSupported();
- static bool screenShareX11Available();
public slots:
void sendInvite(const QString &roomid, webrtc::CallType, unsigned int windowIndex = 0);
@@ -80,8 +78,9 @@ public slots:
mtx::events::voip::CallHangUp::Reason = mtx::events::voip::CallHangUp::Reason::UserHangUp);
void rejectInvite();
void setupScreenShareXDP();
- void setScreenShareType(webrtc::ScreenShareType);
+ void setScreenShareType(unsigned int index);
void closeScreenShare();
+ QStringList screenShareTypeList();
QStringList windowList();
void previewWindow(unsigned int windowIndex) const;
@@ -126,6 +125,7 @@ private:
std::vector<std::string> turnURIs_;
QTimer turnServerTimer_;
QMediaPlayer player_;
+ std::vector<webrtc::ScreenShareType> screenShareTypes_;
std::vector<std::pair<QString, uint32_t>> windows_;
std::vector<std::string> rejectCallPartyIDs_;
|