Skip to content

Commit

Permalink
update scene label when scene is renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Cooper committed Jan 30, 2022
1 parent 2e7ba97 commit b00fb8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ActiveSceneDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ ActiveSceneDock::ActiveSceneDock(QWidget *parent)

ActiveSceneDock::~ActiveSceneDock() {
if (currentScene) {
auto *signalHandler = obs_source_get_signal_handler(currentScene);
if (signalHandler) {
signal_handler_disconnect(signalHandler, "rename",
&ActiveSceneDock::currentSceneRenamed, this);
}
obs_source_release(currentScene);
}
}
Expand All @@ -37,6 +42,11 @@ void ActiveSceneDock::updateCurrentScene(obs_source_t *newScene,
return;
}
if (currentScene) {
auto *signalHandler = obs_source_get_signal_handler(currentScene);
if (signalHandler) {
signal_handler_disconnect(signalHandler, "rename",
&ActiveSceneDock::currentSceneRenamed, this);
}
obs_source_release(currentScene);
currentScene = nullptr;
}
Expand All @@ -47,6 +57,12 @@ void ActiveSceneDock::updateCurrentScene(obs_source_t *newScene,
obs_source_addref(newScene);
currentScene = newScene;

auto *signalHandler = obs_source_get_signal_handler(newScene);
if (signalHandler) {
signal_handler_connect(signalHandler, "rename",
&ActiveSceneDock::currentSceneRenamed, this);
}

currentSceneTimer.start();
if (timerId < 0) {
timerId = startTimer(75);
Expand All @@ -70,6 +86,14 @@ void ActiveSceneDock::timerEvent(QTimerEvent *event) {
}
}

void ActiveSceneDock::currentSceneRenamed(void *data, calldata_t *cd) {
auto *dock = static_cast<ActiveSceneDock *>(data);
const auto *newName = calldata_string(cd, "new_name");
if (newName) {
dock->sceneLabel->setText(QString::fromUtf8(newName));
}
}

void ActiveSceneDock::updateTimerText() {
qint64 elapsed = 0;
if (currentScene) {
Expand Down
1 change: 1 addition & 0 deletions ActiveSceneDock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class ActiveSceneDock : public QDockWidget {

protected:
void timerEvent(QTimerEvent *event) override;
static void currentSceneRenamed(void *data, calldata_t *cd);
void updateTimerText();
};
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Update scene label when scene is renamed

## 0.1.1

- Change dock title to "Active Scene" from "Scene Timer"
Expand Down

0 comments on commit b00fb8c

Please sign in to comment.