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

Refactor OBS source ID comparison to use strncmp for text sources #110

Merged
merged 1 commit into from
Aug 21, 2024
Merged
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
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