From 8cabe24b7789ee95f7a5abbe3ab15d8d6a73ca61 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Thu, 17 Nov 2022 22:19:12 -0800 Subject: [PATCH] eventhandler: Add `ScreenshotSaved` event No, this does not trigger with `Get/SaveScreenshot`. I've tried to make that super clear in the docs. Hopefully people don't get too confused. --- src/eventhandler/EventHandler.cpp | 17 +++++++++++------ src/eventhandler/EventHandler.h | 5 ++++- src/eventhandler/EventHandler_Ui.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/eventhandler/EventHandler.cpp b/src/eventhandler/EventHandler.cpp index f3b0c98a..165212e7 100644 --- a/src/eventhandler/EventHandler.cpp +++ b/src/eventhandler/EventHandler.cpp @@ -353,12 +353,6 @@ void EventHandler::OnFrontendEvent(enum obs_frontend_event event, void *private_ blog_debug("[EventHandler::OnFrontendEvent] Finished."); break; - case OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED: - eventHandler->HandleStudioModeStateChanged(true); - break; - case OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED: - eventHandler->HandleStudioModeStateChanged(false); - break; // Config case OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING: { @@ -477,6 +471,17 @@ void EventHandler::OnFrontendEvent(enum obs_frontend_event event, void *private_ eventHandler->HandleReplayBufferSaved(); break; + // Ui + case OBS_FRONTEND_EVENT_STUDIO_MODE_ENABLED: + eventHandler->HandleStudioModeStateChanged(true); + break; + case OBS_FRONTEND_EVENT_STUDIO_MODE_DISABLED: + eventHandler->HandleStudioModeStateChanged(false); + break; + case OBS_FRONTEND_EVENT_SCREENSHOT_TAKEN: + eventHandler->HandleScreenshotSaved(); + break; + default: break; } diff --git a/src/eventhandler/EventHandler.h b/src/eventhandler/EventHandler.h index fa50f1bd..ce101f36 100644 --- a/src/eventhandler/EventHandler.h +++ b/src/eventhandler/EventHandler.h @@ -78,7 +78,6 @@ private: // General void HandleExitStarted(); - void HandleStudioModeStateChanged(bool enabled); // Config void HandleCurrentSceneCollectionChanging(); @@ -170,4 +169,8 @@ private: static void HandleMediaInputPlaybackEnded(void *param, calldata_t *data); // Direct callback void HandleMediaInputActionTriggered(obs_source_t *source, ObsMediaInputAction action); + + // Ui + void HandleStudioModeStateChanged(bool enabled); + void HandleScreenshotSaved(); }; diff --git a/src/eventhandler/EventHandler_Ui.cpp b/src/eventhandler/EventHandler_Ui.cpp index 633baf8a..2170269f 100644 --- a/src/eventhandler/EventHandler_Ui.cpp +++ b/src/eventhandler/EventHandler_Ui.cpp @@ -38,3 +38,27 @@ void EventHandler::HandleStudioModeStateChanged(bool enabled) eventData["studioModeEnabled"] = enabled; BroadcastEvent(EventSubscription::Ui, "StudioModeStateChanged", eventData); } + +/** + * A screenshot has been saved. + * + * Note: Triggered for the screenshot feature available in `Settings -> Hotkeys -> Screenshot Output` ONLY. + * Applications using `Get/SaveSourceScreenshot` should implement a `CustomEvent` if this kind of inter-client + * communication is desired. + * + * @dataField savedScreenshotPath | String | Path of the saved image file + * + * @eventType ScreenshotSaved + * @eventSubscription Ui + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.1.0 + * @api events + * @category ui + */ +void EventHandler::HandleScreenshotSaved() +{ + json eventData; + eventData["savedScreenshotPath"] = Utils::Obs::StringHelper::GetLastScreenshotFileName(); + BroadcastEvent(EventSubscription::Ui, "ScreenshotSaved", eventData); +}