Skip to content

Commit

Permalink
UI: Move projector rename signal
Browse files Browse the repository at this point in the history
This moves the renaming of projectors from OBSBasic to OBSProjector.
  • Loading branch information
cg2121 authored and tt2468 committed May 12, 2024
1 parent 023d9bd commit cd918a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 0 additions & 5 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3344,11 +3344,6 @@ void OBSBasic::RenameSources(OBSSource source, QString newName,
volumes[i]->SetName(newName);
}

for (size_t i = 0; i < projectors.size(); i++) {
if (projectors[i]->GetSource() == source)
projectors[i]->RenameProjector(prevName, newName);
}

if (vcamConfig.type == VCamOutputType::SourceOutput &&
prevName == QString::fromStdString(vcamConfig.source))
vcamConfig.source = newName.toStdString();
Expand Down
19 changes: 17 additions & 2 deletions UI/window-projector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
{
OBSSource source = GetSource();
if (source) {
destroyedSignal.Connect(obs_source_get_signal_handler(source),
"destroy", OBSSourceDestroyed, this);
sigs.emplace_back(obs_source_get_signal_handler(source),
"rename", OBSSourceRenamed, this);
sigs.emplace_back(obs_source_get_signal_handler(source),
"destroy", OBSSourceDestroyed, this);
}

isAlwaysOnTop = config_get_bool(GetGlobalConfig(), "BasicWindow",
Expand Down Expand Up @@ -106,6 +108,8 @@ OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,

OBSProjector::~OBSProjector()
{
sigs.clear();

bool isMultiview = type == ProjectorType::Multiview;
obs_display_remove_draw_callback(
GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender,
Expand Down Expand Up @@ -215,6 +219,17 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
endRegion();
}

void OBSProjector::OBSSourceRenamed(void *data, calldata_t *params)
{
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
QString oldName = calldata_string(params, "prev_name");
QString newName = calldata_string(params, "new_name");

QMetaObject::invokeMethod(window, "RenameProjector",
Q_ARG(QString, oldName),
Q_ARG(QString, newName));
}

void OBSProjector::OBSSourceDestroyed(void *data, calldata_t *)
{
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
Expand Down
5 changes: 3 additions & 2 deletions UI/window-projector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class OBSProjector : public OBSQTDisplay {

private:
OBSWeakSourceAutoRelease weakSource;
OBSSignal destroyedSignal;
std::vector<OBSSignal> sigs;

static void OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy);
static void OBSRender(void *data, uint32_t cx, uint32_t cy);
static void OBSSourceRenamed(void *data, calldata_t *params);
static void OBSSourceDestroyed(void *data, calldata_t *params);

void mousePressEvent(QMouseEvent *event) override;
Expand Down Expand Up @@ -53,6 +54,7 @@ private slots:
void OpenWindowedProjector();
void AlwaysOnTopToggled(bool alwaysOnTop);
void ScreenRemoved(QScreen *screen_);
void RenameProjector(QString oldName, QString newName);

public:
OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
Expand All @@ -63,7 +65,6 @@ private slots:
ProjectorType GetProjectorType();
int GetMonitor();
static void UpdateMultiviewProjectors();
void RenameProjector(QString oldName, QString newName);
void SetHideCursor();

bool IsAlwaysOnTop() const;
Expand Down

0 comments on commit cd918a7

Please sign in to comment.