diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index 9383ca7e3..99149bb88 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -132,6 +132,7 @@ const std::unordered_map RequestHandler::_han {"SetSceneItemTransform", &RequestHandler::SetSceneItemTransform}, {"GetSceneItemEnabled", &RequestHandler::GetSceneItemEnabled}, {"SetSceneItemEnabled", &RequestHandler::SetSceneItemEnabled}, + {"ToggleSceneItemEnabled", &RequestHandler::ToggleSceneItemEnabled}, {"GetSceneItemLocked", &RequestHandler::GetSceneItemLocked}, {"SetSceneItemLocked", &RequestHandler::SetSceneItemLocked}, {"GetSceneItemIndex", &RequestHandler::GetSceneItemIndex}, diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index a3c24963c..c22a68808 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -151,6 +151,7 @@ class RequestHandler { RequestResult SetSceneItemTransform(const Request &); RequestResult GetSceneItemEnabled(const Request &); RequestResult SetSceneItemEnabled(const Request &); + RequestResult ToggleSceneItemEnabled(const Request &); RequestResult GetSceneItemLocked(const Request &); RequestResult SetSceneItemLocked(const Request &); RequestResult GetSceneItemIndex(const Request &); diff --git a/src/requesthandler/RequestHandler_SceneItems.cpp b/src/requesthandler/RequestHandler_SceneItems.cpp index 0c5024a04..8f6651cb6 100644 --- a/src/requesthandler/RequestHandler_SceneItems.cpp +++ b/src/requesthandler/RequestHandler_SceneItems.cpp @@ -525,6 +525,40 @@ RequestResult RequestHandler::SetSceneItemEnabled(const Request &request) return RequestResult::Success(); } +/** + * Toggles the enable state of a scene item. + * + * Scenes and Groups + * + * @requestField sceneName | String | Name of the scene the item is in + * @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0 + * + * @responseField sceneItemEnabled | Boolean | Whether the scene item has been enabled. `true` for enabled, `false` for disabled + * + * @requestType ToggleSceneItemEnabled + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.3.0 + * @api requests + * @category scene items + */ +RequestResult RequestHandler::ToggleSceneItemEnabled(const Request &request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + OBSSceneItemAutoRelease sceneItem = request.ValidateSceneItem("sceneName", "sceneItemId", statusCode, comment, + OBS_WEBSOCKET_SCENE_FILTER_SCENE_OR_GROUP); + if (!sceneItem) + return RequestResult::Error(statusCode, comment); + + bool sceneItemEnabled = !obs_sceneitem_visible(sceneItem); + obs_sceneitem_set_visible(sceneItem, sceneItemEnabled); + + json responseData; + responseData["sceneItemEnabled"] = sceneItemEnabled; + return RequestResult::Success(responseData); +} + /** * Gets the lock state of a scene item. *