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
This commit is contained in:
jp9000 2020-02-27 04:38:24 -08:00
parent ffe4c767c3
commit 764d5a2d3f
2 changed files with 21 additions and 7 deletions

View File

@ -1899,7 +1899,7 @@ static bool use_scaling_callback(obs_properties_t *ppts, obs_property_t *p,
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 *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);
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);
bfree(class);
@ -1918,14 +1918,15 @@ static void insert_preserved_val(obs_property_t *p, const char *val)
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;
bool match = false;
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) {
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) {
insert_preserved_val(p, cur_val);
insert_preserved_val(p, cur_val, idx);
return true;
}
@ -1950,6 +1951,13 @@ static bool window_changed_callback(obs_properties_t *ppts, obs_property_t *p,
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};
#define NUM_DEFAULT_SCALE_VALS \

View File

@ -286,6 +286,11 @@ static bool wc_capture_method_changed(obs_properties_t *props,
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,
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);
check_window_property_setting(props, p, settings, "window", 0);
return true;
}