mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-03-05 23:26:13 -05:00
UI: Add Start/Stop Recording/Streaming hotkeys
This commit is contained in:
@@ -662,6 +662,7 @@ void OBSBasic::OBSInit()
|
||||
obs_load_all_modules();
|
||||
|
||||
ResetOutputs();
|
||||
CreateHotkeys();
|
||||
|
||||
if (!InitService())
|
||||
throw "Failed to initialize service";
|
||||
@@ -750,6 +751,77 @@ void OBSBasic::HotkeyTriggered(void *data, obs_hotkey_id id, bool pressed)
|
||||
Q_ARG(obs_hotkey_id, id), Q_ARG(bool, pressed));
|
||||
}
|
||||
|
||||
void OBSBasic::CreateHotkeys()
|
||||
{
|
||||
auto LoadHotkeyData = [&](const char *name) -> OBSData
|
||||
{
|
||||
const char *info = config_get_string(basicConfig,
|
||||
"Hotkeys", name);
|
||||
if (!info)
|
||||
return {};
|
||||
|
||||
obs_data_t *data = obs_data_create_from_json(info);
|
||||
if (!data)
|
||||
return {};
|
||||
|
||||
OBSData res = data;
|
||||
obs_data_release(data);
|
||||
return res;
|
||||
};
|
||||
|
||||
auto LoadHotkeyPair = [&](obs_hotkey_pair_id id, const char *name0,
|
||||
const char *name1)
|
||||
{
|
||||
obs_data_array_t *array0 =
|
||||
obs_data_get_array(LoadHotkeyData(name0), "bindings");
|
||||
obs_data_array_t *array1 =
|
||||
obs_data_get_array(LoadHotkeyData(name1), "bindings");
|
||||
|
||||
obs_hotkey_pair_load(id, array0, array1);
|
||||
obs_data_array_release(array0);
|
||||
obs_data_array_release(array1);
|
||||
};
|
||||
|
||||
#define MAKE_CALLBACK(pred, method) \
|
||||
[](void *data, obs_hotkey_pair_id, obs_hotkey_t*, bool pressed) \
|
||||
{ \
|
||||
OBSBasic &basic = *static_cast<OBSBasic*>(data); \
|
||||
if (pred && pressed) { \
|
||||
method(); \
|
||||
return true; \
|
||||
} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
streamingHotkeys = obs_hotkey_pair_register_frontend(
|
||||
"OBSBasic.StartStreaming",
|
||||
Str("Basic.Hotkeys.StartStreaming"),
|
||||
"OBSBasic.StopStreaming",
|
||||
Str("Basic.Hotkeys.StopStreaming"),
|
||||
MAKE_CALLBACK(!basic.outputHandler->StreamingActive(),
|
||||
basic.StartStreaming),
|
||||
MAKE_CALLBACK(basic.outputHandler->StreamingActive(),
|
||||
basic.StopStreaming),
|
||||
this, this);
|
||||
LoadHotkeyPair(streamingHotkeys,
|
||||
"OBSBasic.StartStreaming", "OBSBasic.StopStreaming");
|
||||
|
||||
recordingHotkeys = obs_hotkey_pair_register_frontend(
|
||||
"OBSBasic.StartRecording",
|
||||
Str("Basic.Hotkeys.StartRecording"),
|
||||
"OBSBasic.StopRecording",
|
||||
Str("Basic.Hotkeys.StopRecording"),
|
||||
MAKE_CALLBACK(!basic.outputHandler->RecordingActive(),
|
||||
basic.StartRecording),
|
||||
MAKE_CALLBACK(basic.outputHandler->RecordingActive(),
|
||||
basic.StopRecording),
|
||||
this, this);
|
||||
LoadHotkeyPair(recordingHotkeys,
|
||||
"OBSBasic.StartRecording", "OBSBasic.StopRecording");
|
||||
|
||||
#undef MAKE_CALLBACK
|
||||
}
|
||||
|
||||
OBSBasic::~OBSBasic()
|
||||
{
|
||||
bool previewEnabled = obs_preview_enabled();
|
||||
@@ -764,6 +836,8 @@ OBSBasic::~OBSBasic()
|
||||
os_cpu_usage_info_destroy(cpuUsageInfo);
|
||||
|
||||
obs_hotkey_set_callback_routing_func(nullptr, nullptr);
|
||||
obs_hotkey_pair_unregister(streamingHotkeys);
|
||||
obs_hotkey_pair_unregister(recordingHotkeys);
|
||||
|
||||
service = nullptr;
|
||||
outputHandler.reset();
|
||||
|
||||
Reference in New Issue
Block a user