1
0
Эх сурвалжийг харах

win-capture: Hide settings if Automatic is WGC

jpark37 5 жил өмнө
parent
commit
cce9fb7f95

+ 76 - 59
plugins/win-capture/window-capture.c

@@ -48,7 +48,6 @@ struct window_capture {
 	char *executable;
 	enum window_capture_method method;
 	enum window_priority priority;
-	bool auto_choose_method;
 	bool cursor;
 	bool compatibility;
 	bool use_wildcards; /* TODO */
@@ -68,6 +67,53 @@ struct window_capture {
 	RECT last_rect;
 };
 
+static const char *wgc_partial_match_classes[] = {
+	"Chrome",
+	"Mozilla",
+	NULL,
+};
+
+static const char *wgc_whole_match_classes[] = {
+	"ApplicationFrameWindow",
+	"Windows.UI.Core.CoreWindow",
+	"XLMAIN",        /* excel*/
+	"PPTFrameClass", /* powerpoint */
+	"OpusApp",       /* word */
+	NULL,
+};
+
+static enum window_capture_method
+choose_method(enum window_capture_method method, bool wgc_supported,
+	      const char *current_class)
+{
+	if (method != METHOD_AUTO) {
+		if (method == METHOD_WGC && !wgc_supported)
+			method = METHOD_BITBLT;
+		return method;
+	}
+
+	if (!current_class)
+		return METHOD_BITBLT;
+
+	const char **class = wgc_partial_match_classes;
+	while (*class) {
+		if (astrstri(current_class, *class) != NULL) {
+			return METHOD_WGC;
+		}
+		class ++;
+	}
+
+	class = wgc_whole_match_classes;
+	while (*class) {
+		if (astrcmpi(current_class, *class) == 0) {
+			return METHOD_WGC;
+		}
+		class ++;
+	}
+
+	return METHOD_BITBLT;
+}
+
 static void update_settings(struct window_capture *wc, obs_data_t *s)
 {
 	int method = (int)obs_data_get_int(s, "method");
@@ -88,13 +134,8 @@ static void update_settings(struct window_capture *wc, obs_data_t *s)
 		blog(LOG_DEBUG, "\tclass:      %s", wc->class);
 	}
 
-	if (!wc->wgc_supported) {
-		method = METHOD_BITBLT;
-	}
-
-	wc->method = method;
+	wc->method = choose_method(method, wc->wgc_supported, wc->class);
 	wc->priority = (enum window_priority)priority;
-	wc->auto_choose_method = (method == METHOD_AUTO);
 	wc->cursor = obs_data_get_bool(s, "cursor");
 	wc->use_wildcards = obs_data_get_bool(s, "use_wildcards");
 	wc->compatibility = obs_data_get_bool(s, "compatibility");
@@ -213,17 +254,36 @@ static void wc_defaults(obs_data_t *defaults)
 	obs_data_set_default_bool(defaults, "compatibility", false);
 }
 
+static void update_settings_visibility(obs_properties_t *props,
+				       enum window_capture_method method)
+{
+	const bool bitblt_options = method == METHOD_BITBLT;
+
+	obs_property_t *p = obs_properties_get(props, "cursor");
+	obs_property_set_visible(p, bitblt_options);
+
+	p = obs_properties_get(props, "compatibility");
+	obs_property_set_visible(p, bitblt_options);
+}
+
 static bool wc_capture_method_changed(obs_properties_t *props,
 				      obs_property_t *p, obs_data_t *settings)
 {
-	const int method = (int)obs_data_get_int(settings, "method");
-	const bool show_options = method != METHOD_WGC;
+	struct window_capture *wc = obs_properties_get_param(props);
+	update_settings(wc, settings);
 
-	p = obs_properties_get(props, "cursor");
-	obs_property_set_visible(p, show_options);
+	update_settings_visibility(props, wc->method);
 
-	p = obs_properties_get(props, "compatibility");
-	obs_property_set_visible(p, show_options);
+	return true;
+}
+
+static bool wc_window_changed(obs_properties_t *props, obs_property_t *p,
+			      obs_data_t *settings)
+{
+	struct window_capture *wc = obs_properties_get_param(props);
+	update_settings(wc, settings);
+
+	update_settings_visibility(props, wc->method);
 
 	return true;
 }
@@ -233,6 +293,8 @@ static obs_properties_t *wc_properties(void *data)
 	struct window_capture *wc = data;
 
 	obs_properties_t *ppts = obs_properties_create();
+	obs_properties_set_param(ppts, wc, NULL);
+
 	obs_property_t *p;
 
 	p = obs_properties_add_list(ppts, "method", TEXT_METHOD,
@@ -247,6 +309,7 @@ static obs_properties_t *wc_properties(void *data)
 				    OBS_COMBO_TYPE_LIST,
 				    OBS_COMBO_FORMAT_STRING);
 	fill_window_list(p, EXCLUDE_MINIMIZED, NULL);
+	obs_property_set_modified_callback(p, wc_window_changed);
 
 	p = obs_properties_add_list(ppts, "priority", TEXT_MATCH_PRIORITY,
 				    OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
@@ -273,48 +336,6 @@ static void wc_hide(void *data)
 	memset(&wc->last_rect, 0, sizeof(wc->last_rect));
 }
 
-static const char *wgc_partial_match_classes[] = {
-	"Chrome",
-	"Mozilla",
-	NULL,
-};
-
-static const char *wgc_whole_match_classes[] = {
-	"ApplicationFrameWindow",
-	"Windows.UI.Core.CoreWindow",
-	"XLMAIN",        /* excel*/
-	"PPTFrameClass", /* powerpoint */
-	"OpusApp",       /* word */
-	NULL,
-};
-
-static void auto_choose_method(struct window_capture *wc)
-{
-	wc->method = METHOD_BITBLT;
-
-	if (!wc->class) {
-		return;
-	}
-
-	const char **class = wgc_partial_match_classes;
-	while (*class) {
-		if (astrstri(wc->class, *class) != NULL) {
-			wc->method = METHOD_WGC;
-			return;
-		}
-		class ++;
-	}
-
-	class = wgc_whole_match_classes;
-	while (*class) {
-		if (astrcmpi(wc->class, *class) == 0) {
-			wc->method = METHOD_WGC;
-			return;
-		}
-		class ++;
-	}
-}
-
 #define RESIZE_CHECK_TIME 0.2f
 #define CURSOR_CHECK_TIME 0.2f
 
@@ -344,10 +365,6 @@ static void wc_tick(void *data, float seconds)
 			wc->capture_winrt = NULL;
 		}
 
-		if (wc->auto_choose_method) {
-			auto_choose_method(wc);
-		}
-
 		wc->check_window_timer = 0.0f;
 
 		wc->window = (wc->method == METHOD_WGC)