diff --git a/src/WSEvents.cpp b/src/WSEvents.cpp index 6922c5392..f2c9e7482 100644 --- a/src/WSEvents.cpp +++ b/src/WSEvents.cpp @@ -143,13 +143,17 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private return; } - if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) { + if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) { + owner->hookTransitionBeginEvent(); + } + else if (event == OBS_FRONTEND_EVENT_SCENE_CHANGED) { owner->OnSceneChange(); } else if (event == OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED) { owner->OnSceneListChange(); } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) { + owner->hookTransitionBeginEvent(); owner->OnSceneCollectionChange(); } else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_LIST_CHANGED) { @@ -159,6 +163,7 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private owner->OnTransitionChange(); } else if (event == OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED) { + owner->hookTransitionBeginEvent(); owner->OnTransitionListChange(); } else if (event == OBS_FRONTEND_EVENT_PROFILE_CHANGED) { @@ -217,6 +222,7 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private owner->OnPreviewSceneChanged(); } else if (event == OBS_FRONTEND_EVENT_EXIT) { + owner->unhookTransitionBeginEvent(); owner->OnExit(); } } @@ -283,9 +289,6 @@ void WSEvents::connectSourceSignals(obs_source_t* source) { signal_handler_connect(sh, "item_select", OnSceneItemSelected, this); signal_handler_connect(sh, "item_deselect", OnSceneItemDeselected, this); } - if (sourceType == OBS_SOURCE_TYPE_TRANSITION) { - signal_handler_connect(sh, "transition_start", OnTransitionBegin, this); - } } void WSEvents::disconnectSourceSignals(obs_source_t* source) { @@ -318,6 +321,33 @@ void WSEvents::disconnectSourceSignals(obs_source_t* source) { signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this); } +void WSEvents::hookTransitionBeginEvent() { + obs_frontend_source_list transitions = {}; + obs_frontend_get_transitions(&transitions); + + for (int i = 0; i < transitions.sources.num; i++) { + obs_source_t* transition = transitions.sources.array[i]; + signal_handler_t* sh = obs_source_get_signal_handler(transition); + signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this); + signal_handler_connect(sh, "transition_start", OnTransitionBegin, this); + } + + obs_frontend_source_list_free(&transitions); +} + +void WSEvents::unhookTransitionBeginEvent() { + obs_frontend_source_list transitions = {}; + obs_frontend_get_transitions(&transitions); + + for (int i = 0; i < transitions.sources.num; i++) { + obs_source_t* transition = transitions.sources.array[i]; + signal_handler_t* sh = obs_source_get_signal_handler(transition); + signal_handler_disconnect(sh, "transition_start", OnTransitionBegin, this); + } + + obs_frontend_source_list_free(&transitions); +} + uint64_t WSEvents::GetStreamingTime() { if (obs_frontend_streaming_active()) return (os_gettime_ns() - _streamStarttime); diff --git a/src/WSEvents.h b/src/WSEvents.h index 9250dc9ee..8a6bbec48 100644 --- a/src/WSEvents.h +++ b/src/WSEvents.h @@ -40,6 +40,9 @@ Q_OBJECT void connectSourceSignals(obs_source_t* source); void disconnectSourceSignals(obs_source_t* source); + void hookTransitionBeginEvent(); + void unhookTransitionBeginEvent(); + uint64_t GetStreamingTime(); const char* GetStreamingTimecode(); uint64_t GetRecordingTime();