Skip to content

Commit c2164b4

Browse files
committed
Add canvas support to move action source visibility
1 parent 1cc2cd7 commit c2164b4

1 file changed

Lines changed: 136 additions & 25 deletions

File tree

move-action-filter.c

Lines changed: 136 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
struct move_action_action {
4040
bool *reverse;
41+
char *canvas_name;
4142
char *scene_name;
4243
char *sceneitem_name;
4344
char *source_name;
@@ -401,49 +402,67 @@ void move_action_update(void *data, obs_data_t *settings)
401402
}
402403

403404
if (start_action == MOVE_ACTION_SOURCE_VISIBILITY) {
405+
const char *canvas_name = obs_data_get_string(settings, "canvas");
406+
if (!move_action->start_action.canvas_name || strcmp(canvas_name, move_action->start_action.canvas_name) != 0) {
407+
bfree(move_action->start_action.canvas_name);
408+
move_action->start_action.canvas_name = bstrdup(canvas_name);
409+
}
404410
const char *scene_name = obs_data_get_string(settings, "scene");
405411
if (!move_action->start_action.scene_name || strcmp(scene_name, move_action->start_action.scene_name) != 0) {
406412
bfree(move_action->start_action.scene_name);
407413
move_action->start_action.scene_name = bstrdup(scene_name);
408414
}
409-
} else if (move_action->start_action.scene_name) {
410-
bfree(move_action->start_action.scene_name);
411-
move_action->start_action.scene_name = NULL;
412-
}
413-
414-
if (end_action == MOVE_ACTION_SOURCE_VISIBILITY) {
415-
const char *scene_name = obs_data_get_string(settings, "end_scene");
416-
if (!move_action->end_action.scene_name || strcmp(scene_name, move_action->end_action.scene_name) != 0) {
417-
bfree(move_action->end_action.scene_name);
418-
move_action->end_action.scene_name = bstrdup(scene_name);
419-
}
420-
} else if (move_action->end_action.scene_name) {
421-
bfree(move_action->end_action.scene_name);
422-
move_action->end_action.scene_name = NULL;
423-
}
424-
425-
if (start_action == MOVE_ACTION_SOURCE_VISIBILITY) {
426415
const char *sceneitem_name = obs_data_get_string(settings, "sceneitem");
427416
if (!move_action->start_action.sceneitem_name ||
428417
strcmp(sceneitem_name, move_action->start_action.sceneitem_name) != 0) {
429418
bfree(move_action->start_action.sceneitem_name);
430419
move_action->start_action.sceneitem_name = bstrdup(sceneitem_name);
431420
}
432-
} else if (move_action->start_action.sceneitem_name) {
433-
bfree(move_action->start_action.sceneitem_name);
434-
move_action->start_action.sceneitem_name = NULL;
421+
} else {
422+
if (move_action->start_action.canvas_name) {
423+
bfree(move_action->start_action.canvas_name);
424+
move_action->start_action.canvas_name = NULL;
425+
}
426+
if (move_action->start_action.scene_name) {
427+
bfree(move_action->start_action.scene_name);
428+
move_action->start_action.scene_name = NULL;
429+
}
430+
if (move_action->start_action.sceneitem_name) {
431+
bfree(move_action->start_action.sceneitem_name);
432+
move_action->start_action.sceneitem_name = NULL;
433+
}
435434
}
436435

437436
if (end_action == MOVE_ACTION_SOURCE_VISIBILITY) {
437+
const char *canvas_name = obs_data_get_string(settings, "end_canvas");
438+
if (!move_action->end_action.canvas_name || strcmp(canvas_name, move_action->end_action.canvas_name) != 0) {
439+
bfree(move_action->end_action.canvas_name);
440+
move_action->end_action.canvas_name = bstrdup(canvas_name);
441+
}
442+
const char *scene_name = obs_data_get_string(settings, "end_scene");
443+
if (!move_action->end_action.scene_name || strcmp(scene_name, move_action->end_action.scene_name) != 0) {
444+
bfree(move_action->end_action.scene_name);
445+
move_action->end_action.scene_name = bstrdup(scene_name);
446+
}
438447
const char *sceneitem_name = obs_data_get_string(settings, "end_sceneitem");
439448
if (!move_action->end_action.sceneitem_name ||
440449
strcmp(sceneitem_name, move_action->end_action.sceneitem_name) != 0) {
441450
bfree(move_action->end_action.sceneitem_name);
442451
move_action->end_action.sceneitem_name = bstrdup(sceneitem_name);
443452
}
444-
} else if (move_action->end_action.sceneitem_name) {
445-
bfree(move_action->end_action.sceneitem_name);
446-
move_action->end_action.sceneitem_name = NULL;
453+
} else {
454+
if (move_action->end_action.canvas_name) {
455+
bfree(move_action->end_action.canvas_name);
456+
move_action->end_action.canvas_name = NULL;
457+
}
458+
if (move_action->end_action.scene_name) {
459+
bfree(move_action->end_action.scene_name);
460+
move_action->end_action.scene_name = NULL;
461+
}
462+
if (move_action->end_action.sceneitem_name) {
463+
bfree(move_action->end_action.sceneitem_name);
464+
move_action->end_action.sceneitem_name = NULL;
465+
}
447466
}
448467

449468
move_action->start_action.enable = obs_data_get_int(settings, "enable");
@@ -533,6 +552,7 @@ static void move_action_actual_destroy(void *data)
533552
move_filter_destroy(&move_action->move_filter);
534553
bfree(move_action->start_action.source_name);
535554
bfree(move_action->start_action.hotkey_name);
555+
bfree(move_action->start_action.canvas_name);
536556
bfree(move_action->start_action.scene_name);
537557
bfree(move_action->start_action.sceneitem_name);
538558
bfree(move_action->start_action.filter_name);
@@ -545,6 +565,7 @@ static void move_action_actual_destroy(void *data)
545565
obs_data_release(move_action->start_action.data);
546566
bfree(move_action->end_action.source_name);
547567
bfree(move_action->end_action.hotkey_name);
568+
bfree(move_action->end_action.canvas_name);
548569
bfree(move_action->end_action.scene_name);
549570
bfree(move_action->end_action.sceneitem_name);
550571
bfree(move_action->end_action.filter_name);
@@ -852,6 +873,16 @@ static bool move_action_duration_type_changed(void *data, obs_properties_t *prop
852873
return true;
853874
}
854875

876+
static bool add_canvas_to_prop_list(void *data, obs_canvas_t *canvas)
877+
{
878+
obs_property_t *p = (obs_property_t *)data;
879+
const char *name = obs_canvas_get_name(canvas);
880+
if (!name || !strlen(name))
881+
return true;
882+
obs_property_list_add_string(p, name, name);
883+
return true;
884+
}
885+
855886
static bool add_source_to_prop_list(void *data, obs_source_t *source)
856887
{
857888
obs_property_t *p = (obs_property_t *)data;
@@ -886,15 +917,20 @@ static bool move_action_action_changed(obs_properties_t *props, obs_property_t *
886917
{
887918
UNUSED_PARAMETER(property);
888919
long long action = obs_data_get_int(settings, "action");
920+
obs_property_t *canvas = obs_properties_get(props, "canvas");
889921
obs_property_t *scene = obs_properties_get(props, "scene");
890922
obs_property_t *sceneitem = obs_properties_get(props, "sceneitem");
891923
if (action == MOVE_ACTION_SOURCE_VISIBILITY) {
924+
obs_property_list_clear(canvas);
892925
obs_property_list_clear(scene);
926+
obs_enum_canvases(add_canvas_to_prop_list, canvas);
893927
obs_enum_scenes(add_source_to_prop_list, scene);
894928
obs_enum_sources(add_group_to_prop_list, scene);
929+
obs_property_set_visible(canvas, true);
895930
obs_property_set_visible(scene, true);
896931
obs_property_set_visible(sceneitem, true);
897932
} else {
933+
obs_property_set_visible(canvas, false);
898934
obs_property_set_visible(scene, false);
899935
obs_property_set_visible(sceneitem, false);
900936
}
@@ -954,15 +990,20 @@ static bool move_action_end_action_changed(obs_properties_t *props, obs_property
954990
{
955991
UNUSED_PARAMETER(property);
956992
long long action = obs_data_get_int(settings, "end_action");
993+
obs_property_t *canvas = obs_properties_get(props, "end_canvas");
957994
obs_property_t *scene = obs_properties_get(props, "end_scene");
958995
obs_property_t *sceneitem = obs_properties_get(props, "end_sceneitem");
959996
if (action == MOVE_ACTION_SOURCE_VISIBILITY) {
997+
obs_property_list_clear(canvas);
960998
obs_property_list_clear(scene);
999+
obs_enum_canvases(add_canvas_to_prop_list, canvas);
9611000
obs_enum_scenes(add_source_to_prop_list, scene);
9621001
obs_enum_sources(add_group_to_prop_list, scene);
1002+
obs_property_set_visible(canvas, true);
9631003
obs_property_set_visible(scene, true);
9641004
obs_property_set_visible(sceneitem, true);
9651005
} else {
1006+
obs_property_set_visible(canvas, false);
9661007
obs_property_set_visible(scene, false);
9671008
obs_property_set_visible(sceneitem, false);
9681009
}
@@ -1018,6 +1059,50 @@ static bool move_action_end_action_changed(obs_properties_t *props, obs_property
10181059
return true;
10191060
}
10201061

1062+
static bool add_scene_to_prop_list(void *data, obs_source_t *source)
1063+
{
1064+
obs_property_t *p = (obs_property_t *)data;
1065+
const char *name = obs_source_get_name(source);
1066+
if (name && strlen(name))
1067+
obs_property_list_add_string(p, name, name);
1068+
return true;
1069+
}
1070+
1071+
static bool move_action_canvas_changed(void *data, obs_properties_t *props, obs_property_t *property, obs_data_t *settings)
1072+
{
1073+
UNUSED_PARAMETER(data);
1074+
UNUSED_PARAMETER(property);
1075+
const char *canvas_name = obs_data_get_string(settings, "canvas");
1076+
1077+
obs_property_t *scene = obs_properties_get(props, "scene");
1078+
obs_property_list_clear(scene);
1079+
1080+
obs_canvas_t *canvas = obs_get_canvas_by_name(canvas_name);
1081+
if (!canvas)
1082+
return true;
1083+
1084+
obs_canvas_enum_scenes(canvas, add_scene_to_prop_list, scene);
1085+
obs_canvas_release(canvas);
1086+
return true;
1087+
}
1088+
1089+
static bool move_action_end_canvas_changed(void *data, obs_properties_t *props, obs_property_t *property, obs_data_t *settings)
1090+
{
1091+
UNUSED_PARAMETER(data);
1092+
UNUSED_PARAMETER(property);
1093+
const char *canvas_name = obs_data_get_string(settings, "end_canvas");
1094+
obs_property_t *scene = obs_properties_get(props, "end_scene");
1095+
obs_property_list_clear(scene);
1096+
1097+
obs_canvas_t *canvas = obs_get_canvas_by_name(canvas_name);
1098+
if (!canvas)
1099+
return true;
1100+
1101+
obs_canvas_enum_scenes(canvas, add_scene_to_prop_list, scene);
1102+
obs_canvas_release(canvas);
1103+
return true;
1104+
}
1105+
10211106
static bool add_sceneitem_to_prop_list(obs_scene_t *scene, obs_sceneitem_t *item, void *data)
10221107
{
10231108
UNUSED_PARAMETER(scene);
@@ -1033,10 +1118,18 @@ static bool move_action_scene_changed(void *data, obs_properties_t *props, obs_p
10331118
{
10341119
UNUSED_PARAMETER(data);
10351120
UNUSED_PARAMETER(property);
1121+
const char *canvas_name = obs_data_get_string(settings, "canvas");
1122+
obs_canvas_t *canvas = canvas_name[0] == '\0' ? obs_get_main_canvas() : obs_get_canvas_by_name(canvas_name);
10361123
const char *scene_name = obs_data_get_string(settings, "scene");
10371124
obs_property_t *sceneitem = obs_properties_get(props, "sceneitem");
10381125
obs_property_list_clear(sceneitem);
1039-
obs_source_t *source = obs_get_source_by_name(scene_name);
1126+
obs_source_t *source = NULL;
1127+
if (canvas) {
1128+
source = obs_canvas_get_source_by_name(canvas, scene_name);
1129+
obs_canvas_release(canvas);
1130+
}
1131+
if (!source)
1132+
source = obs_get_source_by_name(scene_name);
10401133
obs_source_release(source);
10411134
obs_scene_t *scene = obs_scene_from_source(source);
10421135
if (!scene)
@@ -1091,6 +1184,10 @@ static obs_properties_t *move_action_properties(void *data)
10911184
obs_property_list_add_int(p, obs_module_text("WebsocketEvent"), MOVE_ACTION_WEBSOCKET_EVENT);
10921185
obs_property_set_modified_callback(p, move_action_action_changed);
10931186

1187+
p = obs_properties_add_list(start_action, "canvas", obs_module_text("Canvas"), OBS_COMBO_TYPE_EDITABLE,
1188+
OBS_COMBO_FORMAT_STRING);
1189+
obs_property_set_modified_callback2(p, move_action_canvas_changed, data);
1190+
10941191
p = obs_properties_add_list(start_action, "scene", obs_module_text("Scene"), OBS_COMBO_TYPE_EDITABLE,
10951192
OBS_COMBO_FORMAT_STRING);
10961193
obs_property_set_modified_callback2(p, move_action_scene_changed, data);
@@ -1205,6 +1302,10 @@ static obs_properties_t *move_action_properties(void *data)
12051302
obs_property_list_add_int(p, obs_module_text("WebsocketEvent"), MOVE_ACTION_WEBSOCKET_EVENT);
12061303
obs_property_set_modified_callback(p, move_action_end_action_changed);
12071304

1305+
p = obs_properties_add_list(end_action, "end_canvas", obs_module_text("Canvas"), OBS_COMBO_TYPE_EDITABLE,
1306+
OBS_COMBO_FORMAT_STRING);
1307+
obs_property_set_modified_callback2(p, move_action_end_canvas_changed, data);
1308+
12081309
p = obs_properties_add_list(end_action, "end_scene", obs_module_text("Scene"), OBS_COMBO_TYPE_EDITABLE,
12091310
OBS_COMBO_FORMAT_STRING);
12101311
obs_property_set_modified_callback2(p, move_action_end_scene_changed, data);
@@ -1393,7 +1494,17 @@ void move_action_execute(void *data)
13931494
} else if (move_action->action == MOVE_ACTION_SOURCE_VISIBILITY) {
13941495
if (move_action->scene_name && move_action->sceneitem_name && strlen(move_action->scene_name) &&
13951496
strlen(move_action->sceneitem_name)) {
1396-
obs_source_t *scene_source = obs_get_source_by_name(move_action->scene_name);
1497+
1498+
obs_canvas_t *canvas = move_action->canvas_name && move_action->canvas_name[0] != '\0'
1499+
? obs_get_canvas_by_name(move_action->canvas_name)
1500+
: obs_get_main_canvas();
1501+
obs_source_t *scene_source = NULL;
1502+
if (canvas) {
1503+
scene_source = obs_canvas_get_source_by_name(canvas, move_action->scene_name);
1504+
obs_canvas_release(canvas);
1505+
}
1506+
if (!scene_source)
1507+
scene_source = obs_get_source_by_name(move_action->scene_name);
13971508
obs_scene_t *scene = obs_scene_from_source(scene_source);
13981509
if (!scene)
13991510
scene = obs_group_from_source(scene_source);

0 commit comments

Comments
 (0)