فهرست منبع

win-capture: Fix and clarify window capture prioritization

Changes "class" prioritization to attempt to find the window either with
the same title, or the next window of the same window class (window
type), changes "title" prioritization to only find the window based
upon its title, and changes "executable" prioritization to attempt to
find the window with the same title, or the next window of the same
executable.

Additionally changes the text associated with these selections to
clarify that functionality to users.
jp9000 8 سال پیش
والد
کامیت
2e0d237341
2فایلهای تغییر یافته به همراه29 افزوده شده و 27 حذف شده
  1. 3 3
      plugins/win-capture/data/locale/en-US.ini
  2. 26 24
      plugins/win-capture/window-helpers.c

+ 3 - 3
plugins/win-capture/data/locale/en-US.ini

@@ -2,9 +2,9 @@ MonitorCapture="Display Capture"
 WindowCapture="Window Capture"
 WindowCapture="Window Capture"
 WindowCapture.Window="Window"
 WindowCapture.Window="Window"
 WindowCapture.Priority="Window Match Priority"
 WindowCapture.Priority="Window Match Priority"
-WindowCapture.Priority.Title="Window Title"
-WindowCapture.Priority.Class="Window Class"
-WindowCapture.Priority.Exe="Executable Name"
+WindowCapture.Priority.Title="Window title must match"
+WindowCapture.Priority.Class="Match title, otherwise find window of same type"
+WindowCapture.Priority.Exe="Match title, otherwise find window of same executable"
 CaptureCursor="Capture Cursor"
 CaptureCursor="Capture Cursor"
 Compatibility="Multi-adapter Compatibility"
 Compatibility="Multi-adapter Compatibility"
 AllowTransparency="Allow Transparency"
 AllowTransparency="Allow Transparency"

+ 26 - 24
plugins/win-capture/window-helpers.c

@@ -347,41 +347,41 @@ static int window_rating(HWND window,
 	struct dstr cur_class = {0};
 	struct dstr cur_class = {0};
 	struct dstr cur_title = {0};
 	struct dstr cur_title = {0};
 	struct dstr cur_exe   = {0};
 	struct dstr cur_exe   = {0};
-	int         class_val = 1;
-	int         title_val = 1;
-	int         exe_val   = 0;
-	int         total     = 0;
+	int val = 0x7FFFFFFF;
 
 
 	if (!get_window_exe(&cur_exe, window))
 	if (!get_window_exe(&cur_exe, window))
-		return 0;
+		return 0x7FFFFFFF;
 	get_window_title(&cur_title, window);
 	get_window_title(&cur_title, window);
 	get_window_class(&cur_class, window);
 	get_window_class(&cur_class, window);
 
 
-	if (priority == WINDOW_PRIORITY_CLASS)
-		class_val += 3;
-	else if (priority == WINDOW_PRIORITY_TITLE)
-		title_val += 3;
-	else
-		exe_val += 3;
+	bool class_matches = dstr_cmpi(&cur_class, class) == 0;
+	bool exe_matches = dstr_cmpi(&cur_exe, exe) == 0;
+	int title_val = abs(dstr_cmpi(&cur_title, title));
 
 
+	/* always match by name with UWP windows */
 	if (uwp_window) {
 	if (uwp_window) {
-		if (dstr_cmpi(&cur_title, title) == 0 &&
-		    dstr_cmpi(&cur_exe, exe) == 0)
-			total += exe_val + title_val + class_val;
-	} else {
-		if (dstr_cmpi(&cur_class, class) == 0)
-			total += class_val;
-		if (dstr_cmpi(&cur_title, title) == 0)
-			total += title_val;
-		if (dstr_cmpi(&cur_exe, exe) == 0)
-			total += exe_val;
+		if (priority == WINDOW_PRIORITY_EXE && !exe_matches)
+			val = 0x7FFFFFFF;
+		else
+			val = title_val == 0 ? 0 : 0x7FFFFFFF;
+
+	} else if (priority == WINDOW_PRIORITY_CLASS) {
+		val = class_matches ? title_val : 0x7FFFFFFF;
+		if (val != 0x7FFFFFFF && !exe_matches)
+			val += 0x1000;
+
+	} else if (priority == WINDOW_PRIORITY_TITLE) {
+		val = title_val == 0 ? 0 : 0x7FFFFFFF;
+
+	} else if (priority == WINDOW_PRIORITY_EXE) {
+		val = exe_matches ? title_val : 0x7FFFFFFF;
 	}
 	}
 
 
 	dstr_free(&cur_class);
 	dstr_free(&cur_class);
 	dstr_free(&cur_title);
 	dstr_free(&cur_title);
 	dstr_free(&cur_exe);
 	dstr_free(&cur_exe);
 
 
-	return total;
+	return val;
 }
 }
 
 
 HWND find_window(enum window_search_mode mode,
 HWND find_window(enum window_search_mode mode,
@@ -395,7 +395,7 @@ HWND find_window(enum window_search_mode mode,
 
 
 	HWND window      = first_window(mode, &parent, &use_findwindowex);
 	HWND window      = first_window(mode, &parent, &use_findwindowex);
 	HWND best_window = NULL;
 	HWND best_window = NULL;
-	int  best_rating = 0;
+	int  best_rating = 0x7FFFFFFF;
 
 
 	if (!class)
 	if (!class)
 		return NULL;
 		return NULL;
@@ -405,9 +405,11 @@ HWND find_window(enum window_search_mode mode,
 	while (window) {
 	while (window) {
 		int rating = window_rating(window, priority, class, title, exe,
 		int rating = window_rating(window, priority, class, title, exe,
 				uwp_window);
 				uwp_window);
-		if (rating > best_rating) {
+		if (rating < best_rating) {
 			best_rating = rating;
 			best_rating = rating;
 			best_window = window;
 			best_window = window;
+			if (rating == 0)
+				break;
 		}
 		}
 
 
 		window = next_window(window, mode, &parent, use_findwindowex);
 		window = next_window(window, mode, &parent, use_findwindowex);