diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/camera-names.cpp | 34 | ||||
-rw-r--r-- | compat/camera-names.hpp | 3 | ||||
-rw-r--r-- | compat/check-visible.cpp | 9 | ||||
-rw-r--r-- | compat/linkage-macros.hpp | 20 | ||||
-rw-r--r-- | compat/process-list.hpp | 2 | ||||
-rw-r--r-- | compat/qhash.hpp | 26 | ||||
-rw-r--r-- | compat/thread-name.cpp | 14 |
7 files changed, 84 insertions, 24 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp index 69926e5a..5d190943 100644 --- a/compat/camera-names.cpp +++ b/compat/camera-names.cpp @@ -7,11 +7,15 @@ # include <cwchar> # define NO_DSHOW_STRSAFE # include <dshow.h> -#elif defined(__unix) || defined(__linux) || defined(__APPLE__) +#elif defined(__unix) || defined(__linux__) || defined(__APPLE__) # include <unistd.h> #endif -#ifdef __linux +#ifdef __APPLE__ +# include <QCameraInfo> +#endif + +#ifdef __linux__ # include <fcntl.h> # include <sys/ioctl.h> # include <linux/videodev2.h> @@ -24,16 +28,22 @@ int camera_name_to_index(const QString &name) { auto list = get_camera_names(); - auto it = std::find(list.cbegin(), list.cend(), name); + auto it = std::find_if(list.cbegin(), list.cend(), [&name](const auto& tuple) { + const auto& [str, idx] = tuple; + return str == name; + }); if (it != list.cend()) - return std::distance(list.cbegin(), it); + { + const auto& [ str, idx ] = *it; + return idx; + } return -1; } -std::vector<QString> get_camera_names() +std::vector<std::tuple<QString, int>> get_camera_names() { - std::vector<QString> ret; + std::vector<std::tuple<QString, int>> ret; #ifdef _WIN32 // Create the System Device Enumerator. HRESULT hr; @@ -66,7 +76,7 @@ std::vector<QString> get_camera_names() { // Display the name in your UI somehow. QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal))); - ret.push_back(str); + ret.push_back({ str, ret.size() }); } VariantClear(&var); pPropBag->Release(); @@ -81,7 +91,7 @@ std::vector<QString> get_camera_names() pSysDevEnum->Release(); #endif -#ifdef __linux +#ifdef __linux__ for (int i = 0; i < 16; i++) { char buf[32]; snprintf(buf, sizeof(buf), "/dev/video%d", i); @@ -97,10 +107,16 @@ std::vector<QString> get_camera_names() close(fd); continue; } - ret.push_back(QString((const char*)video_cap.card)); + ret.push_back({ QString((const char*)video_cap.card), i}); close(fd); } } #endif +#ifdef __APPLE__ + QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); + for (const QCameraInfo &cameraInfo : cameras) + ret.push_back({ cameraInfo.description(), ret.size() }); +#endif + return ret; } diff --git a/compat/camera-names.hpp b/compat/camera-names.hpp index bda15e81..3585edfe 100644 --- a/compat/camera-names.hpp +++ b/compat/camera-names.hpp @@ -10,9 +10,10 @@ #include <vector> #include <QString> +# include <tuple> #include "export.hpp" -OTR_COMPAT_EXPORT std::vector<QString> get_camera_names(); +OTR_COMPAT_EXPORT std::vector<std::tuple<QString, int>> get_camera_names(); OTR_COMPAT_EXPORT int camera_name_to_index(const QString &name); diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp index f786ca14..4da649c7 100644 --- a/compat/check-visible.cpp +++ b/compat/check-visible.cpp @@ -29,6 +29,15 @@ void set_is_visible(const QWidget& w, bool force) return; } + { + int ndisplays = GetSystemMetrics(SM_CMONITORS); + if (ndisplays > 1) + { + visible = true; + return; + } + } + HWND hwnd = (HWND)w.winId(); if (!force && timer.elapsed_ms() < (visible ? visible_timeout : invisible_timeout)) diff --git a/compat/linkage-macros.hpp b/compat/linkage-macros.hpp index 64c64bdb..f4d0104b 100644 --- a/compat/linkage-macros.hpp +++ b/compat/linkage-macros.hpp @@ -1,14 +1,16 @@ #pragma once -#if defined _MSC_VER -# define OTR_GENERIC_EXPORT __declspec(dllexport) -# define OTR_GENERIC_IMPORT __declspec(dllimport) -#elif defined _WIN32 && !defined __WINE__ -# define OTR_GENERIC_EXPORT __attribute__((dllexport, visibility ("default"))) -# define OTR_GENERIC_IMPORT __attribute__((dllimport)) -#else -# define OTR_GENERIC_EXPORT __attribute__((visibility ("default"))) -# define OTR_GENERIC_IMPORT +#ifndef OTR_GENERIC_EXPORT +# if defined _MSC_VER +# define OTR_GENERIC_EXPORT __declspec(dllexport) +# define OTR_GENERIC_IMPORT __declspec(dllimport) +# elif defined _WIN32 && !defined __WINE__ +# define OTR_GENERIC_EXPORT __attribute__((dllexport, visibility ("default"))) +# define OTR_GENERIC_IMPORT __attribute__((dllimport)) +# else +# define OTR_GENERIC_EXPORT __attribute__((visibility ("default"))) +# define OTR_GENERIC_IMPORT +# endif #endif #if defined __APPLE__ || defined __MINGW32__ diff --git a/compat/process-list.hpp b/compat/process-list.hpp index d1f9999f..782dc0a4 100644 --- a/compat/process-list.hpp +++ b/compat/process-list.hpp @@ -129,7 +129,7 @@ static QStringList get_all_executable_names() } } -#elif defined __linux +#elif defined __linux__ #include <proc/readproc.h> #include <cerrno> diff --git a/compat/qhash.hpp b/compat/qhash.hpp new file mode 100644 index 00000000..5286e97e --- /dev/null +++ b/compat/qhash.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include <functional> + +#include <QtGlobal> +#include <QString> +#include <QHashFunctions> + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + +#include <cstdlib> + +namespace std { +template<> struct hash<QString> +{ + using argument_type = QString; + using result_type = std::size_t; + + std::size_t operator()(const QString& value) const noexcept + { + return (std::size_t) qHash(value); + } +}; +} + +#endif diff --git a/compat/thread-name.cpp b/compat/thread-name.cpp index 504c6f19..08a7d628 100644 --- a/compat/thread-name.cpp +++ b/compat/thread-name.cpp @@ -20,12 +20,9 @@ struct THREADNAME_INFO }; static inline -void set_curthread_name_old(const QString& name_) +void set_curthread_name_old_(const char* name) { - QByteArray str = name_.toLocal8Bit(); - const char* name = str.constData(); HANDLE curthread = GetCurrentThread(); - THREADNAME_INFO info; // NOLINT(cppcoreguidelines-pro-type-member-init) info.dwType = 0x1000; info.szName = name; @@ -41,6 +38,15 @@ void set_curthread_name_old(const QString& name_) { } } + +static inline +void set_curthread_name_old(const QString& name_) +{ + QByteArray str = name_.toLocal8Bit(); + const char* name = str.constData(); + + set_curthread_name_old_(name); +} #else static inline void set_curthread_name_old(const QString&) {} |