From 6c0ff0ada2709269264a4d4d040d1719eb09fe11 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Fri, 8 Mar 2024 10:03:41 +0100 Subject: [PATCH] Add build option to deactivate/activate screensharing --- README.md | 1 + linphone-app/CMakeLists.txt | 4 ++- linphone-app/src/components/camera/Camera.cpp | 1 - .../other/desktop-tools/DesktopToolsLinux.cpp | 28 +++++++++++++---- .../desktop-tools/DesktopToolsMacOsNative.mm | 16 ++++++++++ .../desktop-tools/DesktopToolsWindows.cpp | 26 +++++++++++----- .../src/components/settings/SettingsModel.cpp | 31 ++++--------------- .../src/components/settings/SettingsModel.hpp | 10 ++---- linphone-app/src/config.h.cmake | 1 + .../Form/Buttons/AbstractTextButton.qml | 6 ++-- .../ui/modules/Common/Form/MouseArea.qml | 5 +-- .../ui/modules/Linphone/Menus/IncallMenu.qml | 2 +- linphone-app/ui/views/App/Calls/Incall.qml | 5 +-- .../ui/views/App/Calls/IncallFullscreen.qml | 5 +-- 14 files changed, 84 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 0e5bf2938..7178c83f8 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ Also, more configurations are available in the docker-files folder of linphone-s | ENABLE_BUILD_VERBOSE | Enable the build generation to be more verbose | NO | | ENABLE_DAEMON | Enable the linphone daemon interface. | NO | | ENABLE_PQCRYPTO | Enable post quantum ZRTP. | NO | +| ENABLE_SCREENSHARING | Enable screen sharing. | YES | | ENABLE_STRICT | Build with strict compilator flags e.g. -Wall -Werror | NO | | ENABLE_TESTS | Build with testing binaries of SDK | NO | | ENABLE_TESTS_COMPONENTS | Build libbctoolbox-tester | NO | diff --git a/linphone-app/CMakeLists.txt b/linphone-app/CMakeLists.txt index ce5c1aa8c..d40842fa2 100644 --- a/linphone-app/CMakeLists.txt +++ b/linphone-app/CMakeLists.txt @@ -838,7 +838,9 @@ if(WIN32) find_package(OpenLDAP REQUIRED) target_link_libraries(${TARGET_NAME} wsock32 ws2_32 ${OPENLDAP_LIBRARIES}) endif() - target_link_libraries(${TARGET_NAME} Dwmapi) + if(ENABLE_SCREENSHARING) + target_link_libraries(${TARGET_NAME} Dwmapi) + endif() endif() if(NOT WIN32) diff --git a/linphone-app/src/components/camera/Camera.cpp b/linphone-app/src/components/camera/Camera.cpp index c5cd2860a..defbedf92 100644 --- a/linphone-app/src/components/camera/Camera.cpp +++ b/linphone-app/src/components/camera/Camera.cpp @@ -338,7 +338,6 @@ void Camera::activatePreview(){ mPreviewCounterMutex.lock(); if (++mPreviewCounter == 1) { CoreManager::getInstance()->getCore()->enableVideoPreview(true); - CoreManager::getInstance()->getSettingsModel()->setCaptureWindowId(); } mPreviewCounterMutex.unlock(); } diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.cpp b/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.cpp index 1ca9d8787..12310cf40 100644 --- a/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.cpp +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsLinux.cpp @@ -19,12 +19,12 @@ */ #include "DesktopToolsLinux.hpp" - #include "components/core/CoreManager.hpp" -#include "components/settings/SettingsModel.hpp" #include "components/videoSource/VideoSourceDescriptorModel.hpp" +#include "config.h" #include +#include #include #include #include @@ -53,6 +53,8 @@ void DesktopTools::setScreenSaverStatus(bool status) { emit screenSaverStatusChanged(mScreenSaverStatus); } } + +#ifdef ENABLE_SCREENSHARING class T : public QThread { public: Display *mDisplay; @@ -87,7 +89,7 @@ public: &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state); auto id = event.xbutton.subwindow; QMetaObject::invokeMethod(CoreManager::getInstance(), [id, this]() mutable { - mVideoSourceDescriptorModel->setScreenSharingWindow(reinterpret_cast(id)); + mVideoSourceDescriptorModel->setScreenSharingWindow(reinterpret_cast(id)); }); endLoop = true; } @@ -98,7 +100,10 @@ public: deleteLater(); } }; +#endif void DesktopTools::getWindowIdFromMouse(VideoSourceDescriptorModel *model) { + Q_UNUSED(model) +#ifdef ENABLE_SCREENSHARING const char *displayStr = getenv("DISPLAY"); if (displayStr == NULL) displayStr = ":0"; Display *display = XOpenDisplay(displayStr); // QX11Info::display(); @@ -115,13 +120,21 @@ void DesktopTools::getWindowIdFromMouse(VideoSourceDescriptorModel *model) { t->mWindow = RootWindow(display, screen); // QX11Info::appRootWindow(m_x11_screen); t->mParent = this; t->start(); +#endif } -uintptr_t DesktopTools::getDisplayIndex(void* screenSharing){ - return *(uintptr_t*)(&screenSharing); +uintptr_t DesktopTools::getDisplayIndex(void *screenSharing) { + Q_UNUSED(screenSharing) +#ifdef ENABLE_SCREENSHARING + return *(uintptr_t *)(&screenSharing); +#else + return 0; +#endif } -QRect DesktopTools::getWindowGeometry(void* screenSharing) { +QRect DesktopTools::getWindowGeometry(void *screenSharing) { + Q_UNUSED(screenSharing) +#ifdef ENABLE_SCREENSHARING const char *displayStr = getenv("DISPLAY"); if (displayStr == NULL) displayStr = ":0"; Display *display = XOpenDisplay(displayStr); @@ -133,4 +146,7 @@ QRect DesktopTools::getWindowGeometry(void* screenSharing) { XWindowAttributes attributes; XGetWindowAttributes(display, windowId, &attributes); return QRect(attributes.x, attributes.y, attributes.width, attributes.height); +#else + return QRect(); +#endif } diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOsNative.mm b/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOsNative.mm index 84bdb7069..92a013c6a 100644 --- a/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOsNative.mm +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsMacOsNative.mm @@ -1,4 +1,6 @@ #include "DesktopToolsMacOs.hpp" +#include "config.h" + #import #import #include @@ -20,6 +22,8 @@ void DesktopTools::init(){ void *DesktopTools::getDisplay(int screenIndex){ + Q_UNUSED(screenIndex) +#ifdef ENABLE_SCREENSHARING CGDirectDisplayID displays[screenIndex+1]; CGDisplayCount displayCount; CGGetOnlineDisplayList(screenIndex+1, displays, &displayCount); @@ -27,9 +31,14 @@ void *DesktopTools::getDisplay(int screenIndex){ if(displayCount > screenIndex) display = displays[screenIndex]; return reinterpret_cast(display); +#else + return NULL; +#endif } int DesktopTools::getDisplayIndex(void* screenSharing){ + Q_UNUSED(screenSharing) +#ifdef ENABLE_SCREENSHARING CGDirectDisplayID displayId = *(CGDirectDisplayID*)&screenSharing; int maxDisplayCount = 10; CGDisplayCount displayCount; @@ -42,10 +51,13 @@ int DesktopTools::getDisplayIndex(void* screenSharing){ } maxDisplayCount *= 2; }while(displayCount == maxDisplayCount/2); +#endif return 0; } void DesktopTools::getWindowIdFromMouse(VideoSourceDescriptorModel *model) { + Q_UNUSED(model) +#ifdef ENABLE_SCREENSHARING __block id globalMonitorId; __block id localMonitorId; __block DesktopTools * tools = this; @@ -69,10 +81,13 @@ void DesktopTools::getWindowIdFromMouse(VideoSourceDescriptorModel *model) { emit tools->windowIdSelectionEnded(); return nil; }]; +#endif } QRect DesktopTools::getWindowGeometry(void* screenSharing) { + Q_UNUSED(screenSharing) QRect result; +#ifdef ENABLE_SCREENSHARING CGWindowID windowId = *(CGWindowID*)&screenSharing; CFArrayRef descriptions = CGWindowListCopyWindowInfo(kCGWindowListOptionIncludingWindow, windowId); if(CFArrayGetCount(descriptions) > 0) { @@ -90,5 +105,6 @@ QRect DesktopTools::getWindowGeometry(void* screenSharing) { }else qWarning() << "No description found for Window ID : " << windowId; CFRelease(descriptions); +#endif return result; } diff --git a/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.cpp b/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.cpp index 111c30ac3..6572c7035 100644 --- a/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.cpp +++ b/linphone-app/src/components/other/desktop-tools/DesktopToolsWindows.cpp @@ -50,6 +50,7 @@ void DesktopTools::setScreenSaverStatus(bool status) { emit screenSaverStatusChanged(status); } +#ifdef ENABLE_SCREENSHARING HHOOK hMouseHook; DesktopTools *gTools = nullptr; LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam) { @@ -68,26 +69,37 @@ LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam) { } return CallNextHookEx(hMouseHook, nCode, wParam, lParam); } +#endif void DesktopTools::getWindowIdFromMouse(VideoSourceDescriptorModel *model) { + Q_UNUSED(model) +#ifdef ENABLE_SCREENSHARING gTools = this; gTools->mVideoSourceDescriptorModel = model; emit windowIdSelectionStarted(); HINSTANCE hInstance = GetModuleHandle(NULL); hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, mouseProc, hInstance, NULL); +#endif } -uintptr_t DesktopTools::getDisplayIndex(void* screenSharing) { - return *(uintptr_t*)(&screenSharing); +uintptr_t DesktopTools::getDisplayIndex(void *screenSharing) { + Q_UNUSED(screenSharing) +#ifdef ENABLE_SCREENSHARING + return *(uintptr_t *)(&screenSharing); +#else + return NULL; +#endif } -QRect DesktopTools::getWindowGeometry(void* screenSharing) { +QRect DesktopTools::getWindowGeometry(void *screenSharing) { + Q_UNUSED(screenSharing) QRect result; - HWND windowId = *(HWND*)&screenSharing; +#ifdef ENABLE_SCREENSHARING + HWND windowId = *(HWND *)&screenSharing; RECT area; if (S_OK == DwmGetWindowAttribute(windowId, DWMWA_EXTENDED_FRAME_BOUNDS, &area, sizeof(RECT))) { - result = QRect(area.left + 1, area.top, area.right - area.left, area.bottom - area.top);// +1 for border - }else - qWarning() << "Cannot get attributes from HWND: " << windowId; + result = QRect(area.left + 1, area.top, area.right - area.left, area.bottom - area.top); // +1 for border + } else qWarning() << "Cannot get attributes from HWND: " << windowId; +#endif return result; } diff --git a/linphone-app/src/components/settings/SettingsModel.cpp b/linphone-app/src/components/settings/SettingsModel.cpp index 36a31dd15..1e2db6853 100644 --- a/linphone-app/src/components/settings/SettingsModel.cpp +++ b/linphone-app/src/components/settings/SettingsModel.cpp @@ -594,31 +594,12 @@ void SettingsModel::setVideoDevice(const QString &device) { emit videoDeviceChanged(device); } -void SettingsModel::saveCaptureWindowId(void *windowId) { - mCaptureWindowId = windowId; - //CoreManager::getInstance()->getCore()->setVideoCaptureWindowId(mCaptureWindowId); - emit captureScreenIndexChanged(-1); - qDebug() << -1; -} - -void SettingsModel::saveCaptureScreenIndex(int index) { - mCaptureWindowId = reinterpret_cast(-index); - //CoreManager::getInstance()->getCore()->setVideoCaptureWindowId(mCaptureWindowId); - emit captureScreenIndexChanged(index); - qDebug() << index; -} - -int SettingsModel::getCaptureScreenIndex() { -/* - int64_t id = (int64_t)CoreManager::getInstance()->getCore()->getVideoCaptureWindowId(); - if(id <= 0){ - return -id; - }else*/ - return -1; -} - -void SettingsModel::setCaptureWindowId() { - //CoreManager::getInstance()->getCore()->setVideoCaptureWindowId(mCaptureWindowId); +bool SettingsModel::getIsScreenSharingEnabled() const { +#ifdef ENABLE_SCREENSHARING + return true; +#else + return false; +#endif } // ----------------------------------------------------------------------------- diff --git a/linphone-app/src/components/settings/SettingsModel.hpp b/linphone-app/src/components/settings/SettingsModel.hpp index 74373f6f8..742a33a02 100644 --- a/linphone-app/src/components/settings/SettingsModel.hpp +++ b/linphone-app/src/components/settings/SettingsModel.hpp @@ -104,9 +104,6 @@ class SettingsModel : public QObject { Q_PROPERTY(QStringList videoDevices READ getVideoDevices NOTIFY videoDevicesChanged) Q_PROPERTY(QString videoDevice READ getVideoDevice WRITE setVideoDevice NOTIFY videoDeviceChanged) - Q_PROPERTY( - int captureScreenIndex READ getCaptureScreenIndex WRITE saveCaptureScreenIndex NOTIFY captureScreenIndexChanged) - Q_PROPERTY(QString videoPreset READ getVideoPreset WRITE setVideoPreset NOTIFY videoPresetChanged) Q_PROPERTY(int videoFramerate READ getVideoFramerate WRITE setVideoFramerate NOTIFY videoFramerateChanged) @@ -168,6 +165,7 @@ class SettingsModel : public QObject { waitRegistrationForCallChanged) // Allow call only if the current proxy has been registered Q_PROPERTY(bool incallScreenshotEnabled READ getIncallScreenshotEnabled WRITE setIncallScreenshotEnabled NOTIFY incallScreenshotEnabledChanged) + Q_PROPERTY(bool isScreenSharingEnabled READ getIsScreenSharingEnabled CONSTANT) Q_PROPERTY( bool conferenceEnabled READ getConferenceEnabled WRITE setConferenceEnabled NOTIFY conferenceEnabledChanged) @@ -424,10 +422,7 @@ public: QString getVideoDevice() const; void setVideoDevice(const QString &device); - Q_INVOKABLE void saveCaptureWindowId(void *windowId); - Q_INVOKABLE void saveCaptureScreenIndex(int index); - Q_INVOKABLE int getCaptureScreenIndex(); - void setCaptureWindowId(); + bool getIsScreenSharingEnabled() const; QString getVideoPreset() const; void setVideoPreset(const QString &preset); @@ -826,7 +821,6 @@ signals: void videoAvailableChanged(); void videoDevicesChanged(const QStringList &devices); void videoDeviceChanged(const QString &device); - void captureScreenIndexChanged(int index); void videoPresetChanged(const QString &preset); void videoFramerateChanged(int framerate); diff --git a/linphone-app/src/config.h.cmake b/linphone-app/src/config.h.cmake index 93157a450..ddbcbf291 100644 --- a/linphone-app/src/config.h.cmake +++ b/linphone-app/src/config.h.cmake @@ -39,5 +39,6 @@ #cmakedefine ENABLE_APP_WEBVIEW "${ENABLE_APP_WEBVIEW}" #cmakedefine QTKEYCHAIN_TARGET_NAME ${QTKEYCHAIN_TARGET_NAME} #cmakedefine PDF_ENABLED +#cmakedefine ENABLE_SCREENSHARING "${ENABLE_SCREENSHARING}" #endif diff --git a/linphone-app/ui/modules/Common/Form/Buttons/AbstractTextButton.qml b/linphone-app/ui/modules/Common/Form/Buttons/AbstractTextButton.qml index 5bac5334c..1909bba15 100644 --- a/linphone-app/ui/modules/Common/Form/Buttons/AbstractTextButton.qml +++ b/linphone-app/ui/modules/Common/Form/Buttons/AbstractTextButton.qml @@ -29,6 +29,7 @@ Item { property alias textColor: button.textColor property bool enabled: true property bool showBorder : false + property bool interactive: true property alias toggled : button.checked property alias button: button property alias radius: button.radius @@ -106,12 +107,13 @@ Item { verticalAlignment: Text.AlignVCenter } - hoverEnabled: true + hoverEnabled: wrappedButton.interactive MouseArea { id: mouseArea anchors.fill: parent - onPressed: mouse.accepted = false + onPressed: mouse.accepted = !interactive + interactive: wrappedButton.interactive } height: parent.height diff --git a/linphone-app/ui/modules/Common/Form/MouseArea.qml b/linphone-app/ui/modules/Common/Form/MouseArea.qml index 17433106c..7ded9e4c5 100644 --- a/linphone-app/ui/modules/Common/Form/MouseArea.qml +++ b/linphone-app/ui/modules/Common/Form/MouseArea.qml @@ -4,8 +4,9 @@ import Common 1.0 import Common.Styles 1.0 Quick.MouseArea { - cursorShape: containsMouse + property bool interactive: true + cursorShape: containsMouse && interactive ? Qt.PointingHandCursor : Qt.ArrowCursor - hoverEnabled: true + hoverEnabled: interactive } diff --git a/linphone-app/ui/modules/Linphone/Menus/IncallMenu.qml b/linphone-app/ui/modules/Linphone/Menus/IncallMenu.qml index 3079bb60e..72f574561 100644 --- a/linphone-app/ui/modules/Linphone/Menus/IncallMenu.qml +++ b/linphone-app/ui/modules/Linphone/Menus/IncallMenu.qml @@ -25,7 +25,7 @@ Rectangle{ property bool isMeAdmin: me && me.adminStatus property bool isParticipantsMenu: false property bool isScreenSharingMenu: false - property bool screenSharingAvailable: conferenceModel && (!conferenceModel.isScreenSharingEnabled || conferenceModel.isLocalScreenSharingEnabled) + property bool screenSharingAvailable: SettingsModel.isScreenSharingEnabled && conferenceModel && (!conferenceModel.isScreenSharingEnabled || conferenceModel.isLocalScreenSharingEnabled) signal close() signal layoutChanging(int layoutMode) diff --git a/linphone-app/ui/views/App/Calls/Incall.qml b/linphone-app/ui/views/App/Calls/Incall.qml index 24ca76eb9..0ca9e0f62 100644 --- a/linphone-app/ui/views/App/Calls/Incall.qml +++ b/linphone-app/ui/views/App/Calls/Incall.qml @@ -256,7 +256,8 @@ Rectangle { // Mode buttons TextButtonB{ id: screenSharingButton - visible: mainItem.isScreenSharingEnabled + visible: mainItem.isScreenSharingEnabled && (SettingsModel.isScreenSharingEnabled || !mainItem.isLocalScreenSharingEnabled) + interactive: mainItem.isLocalScreenSharingEnabled Layout.preferredWidth: fitWidth Icon{ id: screenSharingIcon @@ -279,7 +280,7 @@ Rectangle { onClicked: if(mainItem.isLocalScreenSharingEnabled) conferenceModel.toggleScreenSharing() } ActionButton{ - visible: !screenSharingButton.visible && callModel && mainItem.conferenceModel && callModel.videoEnabled + visible: SettingsModel.isScreenSharingEnabled && !screenSharingButton.visible && callModel && mainItem.conferenceModel && callModel.videoEnabled isCustom: true backgroundRadius: width/2 colorSet: IncallStyle.buttons.screenSharing diff --git a/linphone-app/ui/views/App/Calls/IncallFullscreen.qml b/linphone-app/ui/views/App/Calls/IncallFullscreen.qml index 64bf0d996..9b5325aa7 100644 --- a/linphone-app/ui/views/App/Calls/IncallFullscreen.qml +++ b/linphone-app/ui/views/App/Calls/IncallFullscreen.qml @@ -227,7 +227,8 @@ Window { // Mode buttons TextButtonB{ id: screenSharingButton - visible: window.isScreenSharingEnabled + visible: window.isScreenSharingEnabled && (SettingsModel.isScreenSharingEnabled || !window.isLocalScreenSharingEnabled) + interactive: window.isLocalScreenSharingEnabled Layout.preferredWidth: fitWidth Icon{ id: screenSharingIcon @@ -250,7 +251,7 @@ Window { onClicked: if(window.isLocalScreenSharingEnabled) conferenceModel.toggleScreenSharing() } ActionButton{ - visible: !screenSharingButton.visible && callModel && window.conferenceModel && callModel.videoEnabled + visible: SettingsModel.isScreenSharingEnabled && !screenSharingButton.visible && callModel && window.conferenceModel && callModel.videoEnabled isCustom: true backgroundRadius: width/2 colorSet: IncallStyle.buttons.screenSharing