Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests: Add ToggleSceneItemEnabled #1154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/requesthandler/RequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"SetSceneItemTransform", &RequestHandler::SetSceneItemTransform},
{"GetSceneItemEnabled", &RequestHandler::GetSceneItemEnabled},
{"SetSceneItemEnabled", &RequestHandler::SetSceneItemEnabled},
{"ToggleSceneItemEnabled", &RequestHandler::ToggleSceneItemEnabled},
{"GetSceneItemLocked", &RequestHandler::GetSceneItemLocked},
{"SetSceneItemLocked", &RequestHandler::SetSceneItemLocked},
{"GetSceneItemIndex", &RequestHandler::GetSceneItemIndex},
Expand Down
1 change: 1 addition & 0 deletions src/requesthandler/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &);
Expand Down
34 changes: 34 additions & 0 deletions src/requesthandler/RequestHandler_SceneItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down