From 22e2b73716ff0f0d1012ee2de8910f1159327eb7 Mon Sep 17 00:00:00 2001 From: Warchamp7 Date: Thu, 25 Jun 2026 18:51:37 -0400 Subject: [PATCH] libobs, frontend: Add monitoring hotkeys --- frontend/data/locale/en-US.ini | 2 ++ frontend/widgets/OBSBasic_Hotkeys.cpp | 4 +-- libobs/obs-hotkey.c | 5 +++- libobs/obs-hotkey.h | 3 ++- libobs/obs-internal.h | 3 +++ libobs/obs-source.c | 39 +++++++++++++++++++++++++-- 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/frontend/data/locale/en-US.ini b/frontend/data/locale/en-US.ini index b13b425cb..ef69b12d5 100644 --- a/frontend/data/locale/en-US.ini +++ b/frontend/data/locale/en-US.ini @@ -1454,6 +1454,8 @@ Mute="Mute" Unmute="Unmute" Push-to-mute="Push-to-mute" Push-to-talk="Push-to-talk" +MonitorOn="Enable Monitoring" +MonitorOff="Disable Monitoring" # scene item hotkeys SceneItemShow="Show '%1'" diff --git a/frontend/widgets/OBSBasic_Hotkeys.cpp b/frontend/widgets/OBSBasic_Hotkeys.cpp index cdf5f184c..4cd37abe4 100644 --- a/frontend/widgets/OBSBasic_Hotkeys.cpp +++ b/frontend/widgets/OBSBasic_Hotkeys.cpp @@ -67,8 +67,8 @@ void OBSBasic::InitHotkeys() t.escape = Str("Hotkeys.Escape"); obs_hotkeys_set_translations(&t); - obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"), Str("Push-to-mute"), - Str("Push-to-talk")); + obs_hotkeys_set_audio_hotkeys_translations(Str("Mute"), Str("Unmute"), Str("Push-to-mute"), Str("Push-to-talk"), + Str("MonitorOn"), Str("MonitorOff")); obs_hotkeys_set_sceneitem_hotkeys_translations(Str("SceneItemShow"), Str("SceneItemHide")); diff --git a/libobs/obs-hotkey.c b/libobs/obs-hotkey.c index 0503b3033..dd89db079 100644 --- a/libobs/obs-hotkey.c +++ b/libobs/obs-hotkey.c @@ -1374,7 +1374,8 @@ void obs_hotkey_update_atomic(obs_hotkey_atomic_update_func func, void *data) } void obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *unmute, const char *push_to_mute, - const char *push_to_talk) + const char *push_to_talk, const char *monitor_on, + const char *monitor_off) { #define SET_T(n) \ bfree(obs->hotkeys.n); \ @@ -1383,6 +1384,8 @@ void obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *un SET_T(unmute); SET_T(push_to_mute); SET_T(push_to_talk); + SET_T(monitor_on); + SET_T(monitor_off); #undef SET_T } diff --git a/libobs/obs-hotkey.h b/libobs/obs-hotkey.h index 0fa6ccc45..12e6faa58 100644 --- a/libobs/obs-hotkey.h +++ b/libobs/obs-hotkey.h @@ -134,7 +134,8 @@ EXPORT void obs_hotkeys_set_translations_s(struct obs_hotkeys_translations *tran obs_hotkeys_set_translations_s(translations, sizeof(struct obs_hotkeys_translations)) EXPORT void obs_hotkeys_set_audio_hotkeys_translations(const char *mute, const char *unmute, const char *push_to_mute, - const char *push_to_talk); + const char *push_to_talk, const char *monitor_on, + const char *monitor_off); EXPORT void obs_hotkeys_set_sceneitem_hotkeys_translations(const char *show, const char *hide); diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 6d72cc0b2..5af83c710 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -537,6 +537,8 @@ struct obs_core_hotkeys { char *push_to_talk; char *sceneitem_show; char *sceneitem_hide; + char *monitor_on; + char *monitor_off; }; typedef DARRAY(struct obs_source_info) obs_source_info_array_t; @@ -992,6 +994,7 @@ struct obs_source { struct audio_monitor *monitor; enum obs_monitoring_type monitoring_type; bool monitoring_enabled; + obs_hotkey_pair_id monitor_on_off_key; /* media action queue */ DARRAY(struct media_action) media_actions; diff --git a/libobs/obs-source.c b/libobs/obs-source.c index 36bae2b0b..d659b0b5f 100644 --- a/libobs/obs-source.c +++ b/libobs/obs-source.c @@ -349,10 +349,40 @@ static void obs_source_hotkey_push_to_talk(void *data, obs_hotkey_id id, obs_hot source->user_push_to_talk_pressed = pressed; } +static bool obs_source_hotkey_monitor_on(void *data, obs_hotkey_pair_id id, obs_hotkey_t *key, bool pressed) +{ + UNUSED_PARAMETER(id); + UNUSED_PARAMETER(key); + + struct obs_source *source = data; + + if (!pressed || obs_source_get_monitoring_enabled(source)) + return false; + + obs_source_set_monitoring_enabled(source, true); + return true; +} + +static bool obs_source_hotkey_monitor_off(void *data, obs_hotkey_pair_id id, obs_hotkey_t *key, bool pressed) +{ + UNUSED_PARAMETER(id); + UNUSED_PARAMETER(key); + + struct obs_source *source = data; + + if (!pressed || !obs_source_get_monitoring_enabled(source)) + return false; + + obs_source_set_monitoring_enabled(source, false); + return true; +} + static void obs_source_init_audio_hotkeys(struct obs_source *source) { if (!(source->info.output_flags & OBS_SOURCE_AUDIO) || source->info.type != OBS_SOURCE_TYPE_INPUT) { - source->mute_unmute_key = OBS_INVALID_HOTKEY_ID; + source->mute_unmute_key = OBS_INVALID_HOTKEY_PAIR_ID; + source->monitor_on_off_key = OBS_INVALID_HOTKEY_PAIR_ID; + source->push_to_mute_key = OBS_INVALID_HOTKEY_ID; source->push_to_talk_key = OBS_INVALID_HOTKEY_ID; return; } @@ -362,6 +392,10 @@ static void obs_source_init_audio_hotkeys(struct obs_source *source) obs_source_hotkey_mute, obs_source_hotkey_unmute, source, source); + source->monitor_on_off_key = obs_hotkey_pair_register_source( + source, "libobs.monitor-on", obs->hotkeys.monitor_on, "libobs.monitor-off", obs->hotkeys.monitor_off, + obs_source_hotkey_monitor_on, obs_source_hotkey_monitor_off, source, source); + source->push_to_mute_key = obs_hotkey_register_source(source, "libobs.push-to-mute", obs->hotkeys.push_to_mute, obs_source_hotkey_push_to_mute, source); @@ -459,6 +493,7 @@ static obs_source_t *obs_source_create_internal(const char *id, const char *name } source->mute_unmute_key = OBS_INVALID_HOTKEY_PAIR_ID; + source->monitor_on_off_key = OBS_INVALID_HOTKEY_PAIR_ID; source->push_to_mute_key = OBS_INVALID_HOTKEY_ID; source->push_to_talk_key = OBS_INVALID_HOTKEY_ID; source->last_obs_ver = last_obs_ver; @@ -785,6 +820,7 @@ static void obs_source_destroy_defer(struct obs_source *source) obs_hotkey_unregister(source->push_to_talk_key); obs_hotkey_unregister(source->push_to_mute_key); obs_hotkey_pair_unregister(source->mute_unmute_key); + obs_hotkey_pair_unregister(source->monitor_on_off_key); for (i = 0; i < source->async_cache.num; i++) obs_source_frame_decref(source->async_cache.array[i].frame); @@ -5557,7 +5593,6 @@ void obs_source_remove_audio_capture_callback(obs_source_t *source, obs_source_a pthread_mutex_unlock(&source->audio_cb_mutex); } - void obs_source_set_monitoring_enabled(obs_source_t *source, bool enabled) { struct calldata data;