diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 780df201c..18a516ae9 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -60,6 +60,7 @@ #ifdef _WIN32 #include "win-update/win-update.hpp" +#include "windows.h" #endif #include "ui_OBSBasic.h" @@ -4131,10 +4132,33 @@ void OBSBasic::AddProjectorMenuMonitors(QMenu *parent, QObject *target, QAction *action; QList screens = QGuiApplication::screens(); for (int i = 0; i < screens.size(); i++) { - QRect screenGeometry = screens[i]->geometry(); + QScreen *screen = screens[i]; + QRect screenGeometry = screen->geometry(); + QString name = ""; +#ifdef _WIN32 + DISPLAY_DEVICEA ddev; + ddev.cb = sizeof(ddev); + EnumDisplayDevicesA(screen->name().toStdString().c_str(), 0, + &ddev, 1); + name = ddev.DeviceString; +#elif defined(__APPLE__) + name = screen->name(); +#elif QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) + name = screen->model().simplified(); + + if (name.length() > 1 && name.endsWith("-")) + name.chop(1); +#endif + name = name.simplified(); + + if (name.length() == 0) { + name = QString("%1 %2") + .arg(QTStr("Display")) + .arg(QString::number(i + 1)); + } QString str = - QString("%1 %2: %3x%4 @ %5,%6") - .arg(QTStr("Display"), QString::number(i + 1), + QString("%1: %2x%3 @ %4,%5") + .arg(name, QString::number(screenGeometry.width()), QString::number(screenGeometry.height()), QString::number(screenGeometry.x()), diff --git a/libobs-d3d11/d3d11-duplicator.cpp b/libobs-d3d11/d3d11-duplicator.cpp index 844a86c9a..fb367a453 100644 --- a/libobs-d3d11/d3d11-duplicator.cpp +++ b/libobs-d3d11/d3d11-duplicator.cpp @@ -16,6 +16,8 @@ ******************************************************************************/ #include "d3d11-subsystem.hpp" +#include "util/platform.h" +#include #include static inline bool get_monitor(gs_device_t *device, int monitor_idx, @@ -34,6 +36,16 @@ static inline bool get_monitor(gs_device_t *device, int monitor_idx, return true; } +static inline void get_display_device(DXGI_OUTPUT_DESC *desc, + MONITORINFOEX *moninfo, + DISPLAY_DEVICE *ddev) +{ + moninfo->cbSize = sizeof(MONITORINFOEX); + GetMonitorInfoW(desc->Monitor, moninfo); + ddev->cb = sizeof(*ddev); + EnumDisplayDevices(moninfo->szDevice, 0, ddev, 1); +} + void gs_duplicator::Start() { ComPtr output1; @@ -95,6 +107,10 @@ EXPORT bool device_get_duplicator_monitor_info(gs_device_t *device, return false; } + DISPLAY_DEVICE ddev; + MONITORINFOEX monitorinf; + get_display_device(&desc, &monitorinf, &ddev); + switch (desc.Rotation) { case DXGI_MODE_ROTATION_UNSPECIFIED: case DXGI_MODE_ROTATION_IDENTITY: @@ -119,6 +135,17 @@ EXPORT bool device_get_duplicator_monitor_info(gs_device_t *device, info->cx = desc.DesktopCoordinates.right - info->x; info->cy = desc.DesktopCoordinates.bottom - info->y; + char *devname = NULL; +#ifdef UNICODE + os_wcs_to_utf8_ptr(ddev.DeviceString, 128, &devname); +#else + devname = (char *)bstrdup(ddev.DeviceString); +#endif + info->monitor_name = devname; + bfree(devname); + + info->flags = monitorinf.dwFlags; + return true; } diff --git a/libobs/graphics/graphics.h b/libobs/graphics/graphics.h index 341a55d1a..fd7ad4bdd 100644 --- a/libobs/graphics/graphics.h +++ b/libobs/graphics/graphics.h @@ -181,6 +181,8 @@ struct gs_monitor_info { long y; long cx; long cy; + char *monitor_name; + uint32_t flags; }; struct gs_tvertarray { diff --git a/plugins/win-capture/duplicator-monitor-capture.c b/plugins/win-capture/duplicator-monitor-capture.c index 91a12bb3e..a8798cd30 100644 --- a/plugins/win-capture/duplicator-monitor-capture.c +++ b/plugins/win-capture/duplicator-monitor-capture.c @@ -273,13 +273,32 @@ static bool get_monitor_props(obs_property_t *monitor_list, int monitor_idx) if (!gs_get_duplicator_monitor_info(monitor_idx, &info)) return false; - dstr_catf(&monitor_desc, "%s %d: %ldx%ld @ %ld,%ld", TEXT_MONITOR, - monitor_idx + 1, info.cx, info.cy, info.x, info.y); + struct dstr format_str = {0}; + dstr_copy(&format_str, "%s: %ldx%ld @ %ld,%ld"); + + struct dstr m = {0}; + dstr_copy(&m, info.monitor_name); + if (dstr_is_empty(&m)) { + // Fallback + struct dstr d = {0}; + dstr_catf(&d, "%s %d", TEXT_MONITOR, monitor_idx + 1); + dstr_free(&m); + dstr_copy_dstr(&m, &d); + dstr_free(&d); + } + + if (info.flags & MONITORINFOF_PRIMARY) + dstr_catf(&format_str, " (%s)", TEXT_PRIMARY_MONITOR); + + dstr_catf(&monitor_desc, format_str.array, m.array, info.cx, info.cy, + info.x, info.y); obs_property_list_add_int(monitor_list, monitor_desc.array, monitor_idx); dstr_free(&monitor_desc); + dstr_free(&format_str); + dstr_free(&m); return true; } diff --git a/plugins/win-capture/monitor-capture.c b/plugins/win-capture/monitor-capture.c index e8d43a6f0..5d2f77f49 100644 --- a/plugins/win-capture/monitor-capture.c +++ b/plugins/win-capture/monitor-capture.c @@ -1,4 +1,5 @@ #include +#include #include "dc-capture.h" /* clang-format off */ @@ -176,7 +177,7 @@ static BOOL CALLBACK enum_monitor_props(HMONITOR handle, HDC hdc, LPRECT rect, UNUSED_PARAMETER(rect); obs_property_t *monitor_list = (obs_property_t *)param; - MONITORINFO mi; + MONITORINFOEX mi; size_t monitor_id = 0; struct dstr monitor_desc = {0}; struct dstr resolution = {0}; @@ -187,18 +188,40 @@ static BOOL CALLBACK enum_monitor_props(HMONITOR handle, HDC hdc, LPRECT rect, mi.cbSize = sizeof(mi); GetMonitorInfo(handle, &mi); + DISPLAY_DEVICE ddev; + ddev.cb = sizeof(ddev); + EnumDisplayDevices(mi.szDevice, 0, &ddev, 1); + + char *devname = NULL; +#ifdef UNICODE + os_wcs_to_utf8_ptr(ddev.DeviceString, 128, &devname); +#else + devname = (char *)bstrdup(ddev.DeviceString); +#endif + dstr_catf(&resolution, "%dx%d @ %d,%d", mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, mi.rcMonitor.left, mi.rcMonitor.top); - dstr_copy(&format_string, "%s %d: %s"); + dstr_copy(&format_string, "%s: %s"); if (mi.dwFlags == MONITORINFOF_PRIMARY) { dstr_catf(&format_string, " (%s)", TEXT_PRIMARY_MONITOR); } - dstr_catf(&monitor_desc, format_string.array, TEXT_MONITOR, - monitor_id + 1, resolution.array); + struct dstr m = {0}; + dstr_copy(&m, devname); + dstr_replace(&m, "(", " ("); + if (dstr_is_empty(&m)) { + struct dstr d = {0}; + dstr_catf(&d, "%s %d", TEXT_MONITOR, monitor_id + 1); + dstr_free(&m); + dstr_copy_dstr(&m, &d); + dstr_free(&d); + } + + dstr_catf(&monitor_desc, format_string.array, m.array, + resolution.array); obs_property_list_add_int(monitor_list, monitor_desc.array, (int)monitor_id); @@ -206,6 +229,8 @@ static BOOL CALLBACK enum_monitor_props(HMONITOR handle, HDC hdc, LPRECT rect, dstr_free(&monitor_desc); dstr_free(&resolution); dstr_free(&format_string); + dstr_free(&m); + bfree(devname); return TRUE; }