From d6e835276752e88dcb592198653e3df5f66ec7e9 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Mon, 1 Sep 2014 17:39:56 +0300 Subject: [PATCH] Improved display/monitor name matching. --- od-win32/win32gfx.cpp | 66 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 59bb6ca7..5c414b03 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -295,26 +295,76 @@ void desktop_coords (int *dw, int *dh, int *ax, int *ay, int *aw, int *ah) int target_get_display (const TCHAR *name) { + int found, found2; + + found = -1; + found2 = -1; for (int i = 0; Displays[i].monitorname; i++) { struct MultiDisplay *md = &Displays[i]; - if (!_tcscmp (md->monitorid, name)) - return i + 1; + if (!_tcscmp (md->monitorid, name)) { + if (found < 0) { + found = i + 1; + } else { + found2 = found; + found = -1; + break; + } + } } + if (found >= 0) + return found; + + found = -1; for (int i = 0; Displays[i].monitorname; i++) { struct MultiDisplay *md = &Displays[i]; - if (!_tcscmp (md->adapterid, name)) - return i + 1; + if (!_tcscmp (md->adapterid, name)) { + if (found < 0) { + found = i + 1; + } else { + if (found2 < 0) + found2 = found; + found = -1; + break; + } + } } + if (found >= 0) + return found; + for (int i = 0; Displays[i].monitorname; i++) { struct MultiDisplay *md = &Displays[i]; - if (!_tcscmp (md->adaptername, name)) - return i + 1; + if (!_tcscmp (md->adaptername, name)) { + if (found < 0) { + found = i + 1; + } else { + if (found2 < 0) + found2 = found; + found = -1; + break; + } + } } + if (found >= 0) + return found; + for (int i = 0; Displays[i].monitorname; i++) { struct MultiDisplay *md = &Displays[i]; - if (!_tcscmp (md->adapterid, name)) - return i + 1; + if (!_tcscmp (md->monitorname, name)) { + if (found < 0) { + found = i + 1; + } else { + if (found2 < 0) + found2 = found; + found = -1; + break; + } + } } + if (found >= 0) + return found; + if (found2 >= 0) + return found2; + return -1; } const TCHAR *target_get_display_name (int num, bool friendlyname) -- 2.47.3