瀏覽代碼

win-capture: Preserve current window setting

This re-uses the game capture code for checking whether the original
window still exists or not.  If it doesn't or the name changed, it'll
insert the value at the top of the list so it doesn't automatically
select another when the user opens properties.

Basically, this fixes an issue where opening properties could sometimes
cause it to instantly capture whatever window was at the top of the
list, which is undesirable.

Closes obsproject/obs-studio#2421
jp9000 5 年之前
父節點
當前提交
764d5a2d3f
共有 2 個文件被更改,包括 21 次插入7 次删除
  1. 15 7
      plugins/win-capture/game-capture.c
  2. 6 0
      plugins/win-capture/window-capture.c

+ 15 - 7
plugins/win-capture/game-capture.c

@@ -1899,7 +1899,7 @@ static bool use_scaling_callback(obs_properties_t *ppts, obs_property_t *p,
 	return true;
 	return true;
 }
 }
 
 
-static void insert_preserved_val(obs_property_t *p, const char *val)
+static void insert_preserved_val(obs_property_t *p, const char *val, size_t idx)
 {
 {
 	char *class = NULL;
 	char *class = NULL;
 	char *title = NULL;
 	char *title = NULL;
@@ -1909,8 +1909,8 @@ static void insert_preserved_val(obs_property_t *p, const char *val)
 	build_window_strings(val, &class, &title, &executable);
 	build_window_strings(val, &class, &title, &executable);
 
 
 	dstr_printf(&desc, "[%s]: %s", executable, title);
 	dstr_printf(&desc, "[%s]: %s", executable, title);
-	obs_property_list_insert_string(p, 1, desc.array, val);
-	obs_property_list_item_disable(p, 1, true);
+	obs_property_list_insert_string(p, idx, desc.array, val);
+	obs_property_list_item_disable(p, idx, true);
 
 
 	dstr_free(&desc);
 	dstr_free(&desc);
 	bfree(class);
 	bfree(class);
@@ -1918,14 +1918,15 @@ static void insert_preserved_val(obs_property_t *p, const char *val)
 	bfree(executable);
 	bfree(executable);
 }
 }
 
 
-static bool window_changed_callback(obs_properties_t *ppts, obs_property_t *p,
-				    obs_data_t *settings)
+bool check_window_property_setting(obs_properties_t *ppts, obs_property_t *p,
+				   obs_data_t *settings, const char *val,
+				   size_t idx)
 {
 {
 	const char *cur_val;
 	const char *cur_val;
 	bool match = false;
 	bool match = false;
 	size_t i = 0;
 	size_t i = 0;
 
 
-	cur_val = obs_data_get_string(settings, SETTING_CAPTURE_WINDOW);
+	cur_val = obs_data_get_string(settings, val);
 	if (!cur_val) {
 	if (!cur_val) {
 		return false;
 		return false;
 	}
 	}
@@ -1942,7 +1943,7 @@ static bool window_changed_callback(obs_properties_t *ppts, obs_property_t *p,
 	}
 	}
 
 
 	if (cur_val && *cur_val && !match) {
 	if (cur_val && *cur_val && !match) {
-		insert_preserved_val(p, cur_val);
+		insert_preserved_val(p, cur_val, idx);
 		return true;
 		return true;
 	}
 	}
 
 
@@ -1950,6 +1951,13 @@ static bool window_changed_callback(obs_properties_t *ppts, obs_property_t *p,
 	return false;
 	return false;
 }
 }
 
 
+static bool window_changed_callback(obs_properties_t *ppts, obs_property_t *p,
+				    obs_data_t *settings)
+{
+	return check_window_property_setting(ppts, p, settings,
+					     SETTING_CAPTURE_WINDOW, 1);
+}
+
 static const double default_scale_vals[] = {1.25, 1.5, 2.0, 2.5, 3.0};
 static const double default_scale_vals[] = {1.25, 1.5, 2.0, 2.5, 3.0};
 
 
 #define NUM_DEFAULT_SCALE_VALS \
 #define NUM_DEFAULT_SCALE_VALS \

+ 6 - 0
plugins/win-capture/window-capture.c

@@ -286,6 +286,11 @@ static bool wc_capture_method_changed(obs_properties_t *props,
 	return true;
 	return true;
 }
 }
 
 
+extern bool check_window_property_setting(obs_properties_t *ppts,
+					  obs_property_t *p,
+					  obs_data_t *settings, const char *val,
+					  size_t idx);
+
 static bool wc_window_changed(obs_properties_t *props, obs_property_t *p,
 static bool wc_window_changed(obs_properties_t *props, obs_property_t *p,
 			      obs_data_t *settings)
 			      obs_data_t *settings)
 {
 {
@@ -294,6 +299,7 @@ static bool wc_window_changed(obs_properties_t *props, obs_property_t *p,
 
 
 	update_settings_visibility(props, wc->method);
 	update_settings_visibility(props, wc->method);
 
 
+	check_window_property_setting(props, p, settings, "window", 0);
 	return true;
 	return true;
 }
 }