Skip to content

Commit

Permalink
eventhandler: Add ScreenshotSaved event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tt2468 committed Nov 18, 2022
1 parent 9cfca3c commit 8cabe24
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/eventhandler/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/eventhandler/EventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class EventHandler {

// General
void HandleExitStarted();
void HandleStudioModeStateChanged(bool enabled);

// Config
void HandleCurrentSceneCollectionChanging();
Expand Down Expand Up @@ -170,4 +169,8 @@ class EventHandler {
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();
};
24 changes: 24 additions & 0 deletions src/eventhandler/EventHandler_Ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 8cabe24

Please sign in to comment.