Skip to content

Commit

Permalink
Refactor OBS source ID comparison to use strncmp for text sources (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil authored Aug 21, 2024
1 parent e26d7f0 commit a006cb0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/obs-source-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ inline bool is_obs_source_text(obs_source_t *source)
return false;
}
const auto source_id = obs_source_get_id(source);
return strcmp(source_id, "text_ft2_source_v2") == 0 ||
strcmp(source_id, "text_gdiplus_v2") == 0;
return strncmp(source_id, "text_ft2_source", 15) == 0 ||
strncmp(source_id, "text_gdiplus", 12) == 0;
}

inline bool is_obs_source_text(const std::string &source_name)
Expand Down
6 changes: 3 additions & 3 deletions src/ui/RequestBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void set_form_row_visibility(QFormLayout *layout, QWidget *widget, bool visible)

bool add_sources_to_qcombobox(void *list, obs_source_t *source)
{
const auto source_id = obs_source_get_id(source);
// add all text sources and sources that produce an image (by checking source.output_flags = OBS_SOURCE_VIDEO)
if (!is_obs_source_text(source) &&
((obs_source_get_output_flags(source) & OBS_SOURCE_VIDEO) == 0)) {
Expand All @@ -46,8 +45,9 @@ bool add_sources_to_qcombobox(void *list, obs_source_t *source)

std::string name = obs_source_get_name(source);
std::string prefix = "";
if (strcmp(source_id, "text_ft2_source_v2") == 0 ||
strcmp(source_id, "text_gdiplus_v2") == 0)
const auto source_id = obs_source_get_id(source);
if (strncmp(source_id, "text_ft2_source", 15) == 0 ||
strncmp(source_id, "text_gdiplus", 12) == 0)
prefix = "(Text) ";
else
prefix = "(Image) ";
Expand Down
12 changes: 5 additions & 7 deletions src/ui/obs-ui-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ bool add_sources_to_combobox(void *list_property, obs_source_t *source)
{
// add all text and media sources to the list
auto source_id = obs_source_get_id(source);
if (strcmp(source_id, "text_ft2_source_v2") != 0 &&
strcmp(source_id, "text_gdiplus_v2") != 0 &&
strcmp(source_id, "text_gdiplus_v3") != 0 && strcmp(source_id, "ffmpeg_source") != 0 &&
strcmp(source_id, "image_source") != 0) {
if (strncmp(source_id, "text_ft2_source", 15) != 0 &&
strncmp(source_id, "text_gdiplus", 12) != 0 &&
strcmp(source_id, "ffmpeg_source") != 0 && strcmp(source_id, "image_source") != 0) {
return true;
}

QComboBox *sources = static_cast<QComboBox *>(list_property);
const char *name = obs_source_get_name(source);
std::string name_with_prefix;
// add a prefix to the name to indicate the source type
if (strcmp(source_id, "text_ft2_source_v2") == 0 ||
strcmp(source_id, "text_gdiplus_v3") == 0 ||
strcmp(source_id, "text_gdiplus_v2") == 0) {
if (strncmp(source_id, "text_ft2_source", 15) == 0 ||
strncmp(source_id, "text_gdiplus", 12) == 0) {
name_with_prefix = std::string("(Text) ").append(name);
} else if (strcmp(source_id, "image_source") == 0) {
name_with_prefix = std::string("(Image) ").append(name);
Expand Down

0 comments on commit a006cb0

Please sign in to comment.