mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
requesthandler: Add optional context to TriggerHotkeyByName
This commit is contained in:
parent
7a1c71bb96
commit
f43ef8e2da
@ -233,6 +233,7 @@ RequestResult RequestHandler::GetHotkeyList(const Request &)
|
|||||||
* Triggers a hotkey using its name. See `GetHotkeyList`
|
* Triggers a hotkey using its name. See `GetHotkeyList`
|
||||||
*
|
*
|
||||||
* @requestField hotkeyName | String | Name of the hotkey to trigger
|
* @requestField hotkeyName | String | Name of the hotkey to trigger
|
||||||
|
* @requestField ?contextName | String | Name of context of the hotkey to trigger
|
||||||
*
|
*
|
||||||
* @requestType TriggerHotkeyByName
|
* @requestType TriggerHotkeyByName
|
||||||
* @complexity 3
|
* @complexity 3
|
||||||
@ -248,7 +249,15 @@ RequestResult RequestHandler::TriggerHotkeyByName(const Request &request)
|
|||||||
if (!request.ValidateString("hotkeyName", statusCode, comment))
|
if (!request.ValidateString("hotkeyName", statusCode, comment))
|
||||||
return RequestResult::Error(statusCode, comment);
|
return RequestResult::Error(statusCode, comment);
|
||||||
|
|
||||||
obs_hotkey_t *hotkey = Utils::Obs::SearchHelper::GetHotkeyByName(request.RequestData["hotkeyName"]);
|
std::string contextName;
|
||||||
|
if (request.Contains("contextName")) {
|
||||||
|
if (!request.ValidateOptionalString("contextName", statusCode, comment))
|
||||||
|
return RequestResult::Error(statusCode, comment);
|
||||||
|
|
||||||
|
contextName = request.RequestData["contextName"];
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_hotkey_t *hotkey = Utils::Obs::SearchHelper::GetHotkeyByName(request.RequestData["hotkeyName"], contextName);
|
||||||
if (!hotkey)
|
if (!hotkey)
|
||||||
return RequestResult::Error(RequestStatus::ResourceNotFound, "No hotkeys were found by that name.");
|
return RequestResult::Error(RequestStatus::ResourceNotFound, "No hotkeys were found by that name.");
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ namespace Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace SearchHelper {
|
namespace SearchHelper {
|
||||||
obs_hotkey_t *GetHotkeyByName(std::string name);
|
obs_hotkey_t *GetHotkeyByName(std::string name, std::string context);
|
||||||
obs_source_t *GetSceneTransitionByName(std::string name); // Increments source ref. Use OBSSourceAutoRelease
|
obs_source_t *GetSceneTransitionByName(std::string name); // Increments source ref. Use OBSSourceAutoRelease
|
||||||
obs_sceneitem_t *GetSceneItemByName(obs_scene_t *scene, std::string name,
|
obs_sceneitem_t *GetSceneItemByName(obs_scene_t *scene, std::string name,
|
||||||
int offset = 0); // Increments ref. Use OBSSceneItemAutoRelease
|
int offset = 0); // Increments ref. Use OBSSceneItemAutoRelease
|
||||||
|
@ -19,7 +19,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
|
|||||||
#include "Obs.h"
|
#include "Obs.h"
|
||||||
#include "plugin-macros.generated.h"
|
#include "plugin-macros.generated.h"
|
||||||
|
|
||||||
obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name)
|
obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name, std::string context)
|
||||||
{
|
{
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -27,8 +27,47 @@ obs_hotkey_t *Utils::Obs::SearchHelper::GetHotkeyByName(std::string name)
|
|||||||
auto hotkeys = ArrayHelper::GetHotkeyList();
|
auto hotkeys = ArrayHelper::GetHotkeyList();
|
||||||
|
|
||||||
for (auto hotkey : hotkeys) {
|
for (auto hotkey : hotkeys) {
|
||||||
if (obs_hotkey_get_name(hotkey) == name)
|
if (obs_hotkey_get_name(hotkey) != name)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (context.empty())
|
||||||
return hotkey;
|
return hotkey;
|
||||||
|
|
||||||
|
auto type = obs_hotkey_get_registerer_type(hotkey);
|
||||||
|
if (type == OBS_HOTKEY_REGISTERER_SOURCE) {
|
||||||
|
OBSSourceAutoRelease source = obs_weak_source_get_source((obs_weak_source_t *)obs_hotkey_get_registerer(hotkey));
|
||||||
|
if (!source)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (context != obs_source_get_name(source))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else if (type == OBS_HOTKEY_REGISTERER_OUTPUT) {
|
||||||
|
OBSOutputAutoRelease output = obs_weak_output_get_output((obs_weak_output_t *)obs_hotkey_get_registerer(hotkey));
|
||||||
|
if (!output)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (context != obs_output_get_name(output))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else if (type == OBS_HOTKEY_REGISTERER_ENCODER) {
|
||||||
|
OBSEncoderAutoRelease encoder = obs_weak_encoder_get_encoder((obs_weak_encoder_t *)obs_hotkey_get_registerer(hotkey));
|
||||||
|
if (!encoder)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (context != obs_encoder_get_name(encoder))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
} else if (type == OBS_HOTKEY_REGISTERER_SERVICE) {
|
||||||
|
OBSServiceAutoRelease service = obs_weak_service_get_service((obs_weak_service_t *)obs_hotkey_get_registerer(hotkey));
|
||||||
|
if (!service)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (context != obs_service_get_name(service))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
return hotkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user