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

UI: Add ability to set global scenes #4491

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions UI/data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ LogViewer="Log Viewer"
ShowOnStartup="Show on startup"
OpenFile="Open file"
AddValue="Add %1"
SetAsGlobal="Set as Global"
RemoveAsGlobal="Remove as Global"

# warning if program already open
AlreadyRunning.Title="OBS is already running"
Expand Down
2 changes: 2 additions & 0 deletions UI/data/themes/Acri.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,8 @@ OBSBasic {
qproperty-groupIcon: url(./Dark/sources/group.svg);
qproperty-sceneIcon: url(./Dark/sources/scene.svg);
qproperty-defaultIcon: url(./Dark/sources/default.svg);
qproperty-pinIcon: url(./Dark/pin.svg);
qproperty-pinSelectedIcon: url(:res/images/pin_selected.svg);
}

/* Scene Tree */
Expand Down
2 changes: 2 additions & 0 deletions UI/data/themes/Dark.qss
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ OBSBasic {
qproperty-groupIcon: url(./Dark/sources/group.svg);
qproperty-sceneIcon: url(./Dark/sources/scene.svg);
qproperty-defaultIcon: url(./Dark/sources/default.svg);
qproperty-pinIcon: url(./Dark/pin.svg);
qproperty-pinSelectedIcon: url(:res/images/pin_selected.svg);
}

/* Scene Tree */
Expand Down
3 changes: 3 additions & 0 deletions UI/data/themes/Dark/pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions UI/data/themes/Rachni.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,8 @@ OBSBasic {
qproperty-groupIcon: url(./Dark/sources/group.svg);
qproperty-sceneIcon: url(./Dark/sources/scene.svg);
qproperty-defaultIcon: url(./Dark/sources/default.svg);
qproperty-pinIcon: url(./Dark/pin.svg);
qproperty-pinSelectedIcon: url(:res/images/pin_selected.svg);
}

/* Scene Tree */
Expand Down
2 changes: 2 additions & 0 deletions UI/data/themes/System.qss
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ OBSBasic {
qproperty-groupIcon: url(:res/images/sources/group.svg);
qproperty-sceneIcon: url(:res/images/sources/scene.svg);
qproperty-defaultIcon: url(:res/images/sources/default.svg);
qproperty-pinIcon: url(:res/images/pin.svg);
qproperty-pinSelectedIcon: url(:res/images/pin_selected.svg);
}

/* Scene Tree */
Expand Down
3 changes: 3 additions & 0 deletions UI/forms/images/pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions UI/forms/images/pin_selected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions UI/forms/obs.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<file>images/media/media_restart.svg</file>
<file>images/media/media_stop.svg</file>
<file>images/interact.svg</file>
<file>images/pin.svg</file>
<file>images/pin_selected.svg</file>
</qresource>
<qresource prefix="/settings">
<file>images/settings/output.svg</file>
Expand Down
1 change: 1 addition & 0 deletions UI/scene-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SceneTree::SceneTree(QWidget *parent_) : QListWidget(parent_)
installEventFilter(this);
setDragDropMode(InternalMove);
setMovement(QListView::Snap);
setIconSize(QSize(16, 16));
}

void SceneTree::SetGridMode(bool grid)
Expand Down
20 changes: 20 additions & 0 deletions UI/window-basic-main-icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ void OBSBasic::SetDefaultIcon(const QIcon &icon)
defaultIcon = icon;
}

void OBSBasic::SetPinIcon(const QIcon &icon)
{
pinIcon = icon;
}

void OBSBasic::SetPinSelectedIcon(const QIcon &icon)
{
pinSelectedIcon = icon;
}

QIcon OBSBasic::GetImageIcon() const
{
return imageIcon;
Expand Down Expand Up @@ -186,3 +196,13 @@ QIcon OBSBasic::GetDefaultIcon() const
{
return defaultIcon;
}

QIcon OBSBasic::GetPinIcon() const
{
return pinIcon;
}

QIcon OBSBasic::GetPinSelectedIcon() const
{
return pinSelectedIcon;
}
5 changes: 4 additions & 1 deletion UI/window-basic-main-transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,10 @@ template<typename T> static T GetOBSRef(QListWidgetItem *item)

void OBSBasic::SetCurrentScene(OBSSource scene, bool force)
{
if (!IsPreviewProgramMode()) {
if (SceneIsGlobal(obs_scene_from_source(scene))) {
obs_set_output_source(7, scene);
UpdatePinIcons();
} else if (!IsPreviewProgramMode()) {
TransitionToScene(scene, force);
} else {
OBSSource actualLastScene = OBSGetStrongRef(lastScene);
Expand Down
97 changes: 96 additions & 1 deletion UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ OBSBasic::OBSBasic(QWidget *parent)

connect(ui->scenes, SIGNAL(scenesReordered()), this,
SLOT(ScenesReordered()));

connect(App(), &OBSApp::StyleChanged, this, &OBSBasic::UpdatePinIcons);
}

static void SaveAudioDevice(const char *name, int channel, obs_data_t *parent,
Expand Down Expand Up @@ -513,14 +515,17 @@ static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder,
/* -------------------------------- */

obs_source_t *transition = obs_get_output_source(0);
obs_source_t *global = obs_get_output_source(7);
obs_source_t *currentScene = obs_scene_get_source(scene);
const char *sceneName = obs_source_get_name(currentScene);
const char *programName = obs_source_get_name(curProgramScene);
const char *globalSceneName = obs_source_get_name(global);

const char *sceneCollection = config_get_string(
App()->GlobalConfig(), "Basic", "SceneCollection");

obs_data_set_string(saveData, "current_scene", sceneName);
obs_data_set_string(saveData, "current_global_scene", globalSceneName);
obs_data_set_string(saveData, "current_program_scene", programName);
obs_data_set_array(saveData, "scene_order", sceneOrder);
obs_data_set_string(saveData, "name", sceneCollection);
Expand All @@ -536,6 +541,7 @@ static obs_data_t *GenerateSaveData(obs_data_array_t *sceneOrder,
obs_source_get_name(transition));
obs_data_set_int(saveData, "transition_duration", transitionDuration);
obs_source_release(transition);
obs_source_release(global);

return saveData;
}
Expand Down Expand Up @@ -962,6 +968,8 @@ void OBSBasic::LoadData(obs_data_t *data, const char *file)
obs_data_array_t *groups = obs_data_get_array(data, "groups");
obs_data_array_t *transitions = obs_data_get_array(data, "transitions");
const char *sceneName = obs_data_get_string(data, "current_scene");
const char *globalSceneName =
obs_data_get_string(data, "current_global_scene");
const char *programSceneName =
obs_data_get_string(data, "current_program_scene");
const char *transitionName =
Expand Down Expand Up @@ -989,6 +997,7 @@ void OBSBasic::LoadData(obs_data_t *data, const char *file)
obs_source_t *curScene;
obs_source_t *curProgramScene;
obs_source_t *curTransition;
obs_source_t *curGlobalScene;

if (!name || !*name)
name = curSceneCollection;
Expand Down Expand Up @@ -1038,6 +1047,7 @@ void OBSBasic::LoadData(obs_data_t *data, const char *file)
retryScene:
curScene = obs_get_source_by_name(sceneName);
curProgramScene = obs_get_source_by_name(programSceneName);
curGlobalScene = obs_get_source_by_name(globalSceneName);

/* if the starting scene command line parameter is bad at all,
* fall back to original settings */
Expand All @@ -1056,11 +1066,11 @@ void OBSBasic::LoadData(obs_data_t *data, const char *file)
obs_source_addref(curScene);
}

SetCurrentScene(curScene, true);
if (IsPreviewProgramMode())
TransitionToScene(curProgramScene, true);
obs_source_release(curScene);
obs_source_release(curProgramScene);
obs_source_release(curGlobalScene);

obs_data_array_release(sources);
obs_data_array_release(groups);
Expand Down Expand Up @@ -1175,6 +1185,10 @@ void OBSBasic::LoadData(obs_data_t *data, const char *file)
obs_missing_files_destroy(files);
}

LoadGlobalScenes();
SetCurrentScene(curGlobalScene);
SetCurrentScene(curScene, true);

disableSaving--;

if (api) {
Expand Down Expand Up @@ -4787,6 +4801,16 @@ void OBSBasic::on_scenes_customContextMenuRequested(const QPoint &pos)
connect(pasteFilters, SIGNAL(triggered()), this,
SLOT(ScenePasteFilters()));

popup.addSeparator();

bool global = SceneIsGlobal(GetCurrentScene());
if (!global)
popup.addAction(QTStr("SetAsGlobal"), this,
SLOT(SetSceneAsGlobal()));
else
popup.addAction(QTStr("RemoveAsGlobal"), this,
SLOT(RemoveSceneAsGlobal()));

popup.addSeparator();
popup.addAction(QTStr("Duplicate"), this,
SLOT(DuplicateSelectedScene()));
Expand Down Expand Up @@ -9175,3 +9199,74 @@ void OBSBasic::ShowStatusBarMessage(const QString &message)
ui->statusbar->clearMessage();
ui->statusbar->showMessage(message, 10000);
}

void OBSBasic::LoadGlobalScenes()
{
for (int i = 0; i < ui->scenes->count(); i++) {
QListWidgetItem *item = ui->scenes->item(i);
OBSScene scene = GetOBSRef<OBSScene>(item);

if (SceneIsGlobal(scene))
item->setIcon(GetPinIcon());
}
}

bool OBSBasic::SceneIsGlobal(OBSScene scene)
{
OBSSource source = obs_scene_get_source(scene);
obs_data_t *priv_settings = obs_source_get_private_settings(source);
bool dsk = obs_data_get_bool(priv_settings, "is_dsk");
obs_data_release(priv_settings);

return dsk;
}

void OBSBasic::SetSceneAsGlobal()
{
OBSSource source = GetCurrentSceneSource();

obs_data_t *priv_settings = obs_source_get_private_settings(source);
obs_data_set_bool(priv_settings, "is_dsk", true);
obs_data_release(priv_settings);

QListWidgetItem *item = ui->scenes->currentItem();
item->setIcon(GetPinIcon());

SetCurrentScene(source);
}

void OBSBasic::RemoveSceneAsGlobal()
{
OBSSource source = GetCurrentSceneSource();

obs_data_t *priv_settings = obs_source_get_private_settings(source);
obs_data_set_bool(priv_settings, "is_dsk", false);
obs_data_release(priv_settings);

QListWidgetItem *item = ui->scenes->currentItem();
item->setIcon(QIcon());
obs_set_output_source(7, nullptr);
}

void OBSBasic::UpdatePinIcons()
{
OBSSource globalSource = obs_get_output_source(7);

if (!globalSource)
return;

for (int i = 0; i < ui->scenes->count(); i++) {
QListWidgetItem *item = ui->scenes->item(i);
OBSScene scene = GetOBSRef<OBSScene>(item);
OBSSource sceneSource = obs_scene_get_source(scene);

if (SceneIsGlobal(scene)) {
if (globalSource == sceneSource)
item->setIcon(GetPinSelectedIcon());
else
item->setIcon(GetPinIcon());
}
}

obs_source_release(globalSource);
}
16 changes: 16 additions & 0 deletions UI/window-basic-main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class OBSBasic : public OBSMainWindow {
DESIGNABLE true)
Q_PROPERTY(QIcon defaultIcon READ GetDefaultIcon WRITE SetDefaultIcon
DESIGNABLE true)
Q_PROPERTY(
QIcon pinIcon READ GetPinIcon WRITE SetPinIcon DESIGNABLE true)
Q_PROPERTY(QIcon pinSelectedIcon READ GetPinSelectedIcon WRITE
SetPinSelectedIcon DESIGNABLE true)

friend class OBSAbout;
friend class OBSBasicPreview;
Expand Down Expand Up @@ -526,6 +530,8 @@ class OBSBasic : public OBSMainWindow {
QIcon groupIcon;
QIcon sceneIcon;
QIcon defaultIcon;
QIcon pinIcon;
QIcon pinSelectedIcon;

QIcon GetImageIcon() const;
QIcon GetColorIcon() const;
Expand All @@ -540,6 +546,8 @@ class OBSBasic : public OBSMainWindow {
QIcon GetMediaIcon() const;
QIcon GetBrowserIcon() const;
QIcon GetDefaultIcon() const;
QIcon GetPinIcon() const;
QIcon GetPinSelectedIcon() const;

QSlider *tBar;
bool tBarActive = false;
Expand Down Expand Up @@ -709,6 +717,8 @@ private slots:
void SetGroupIcon(const QIcon &icon);
void SetSceneIcon(const QIcon &icon);
void SetDefaultIcon(const QIcon &icon);
void SetPinIcon(const QIcon &icon);
void SetPinSelectedIcon(const QIcon &icon);

void TBarChanged(int value);
void TBarReleased();
Expand Down Expand Up @@ -1048,6 +1058,12 @@ public slots:
void UpdateContextBar(bool force = false);
void UpdateContextBarDeferred(bool force = false);

bool SceneIsGlobal(OBSScene scene);
void SetSceneAsGlobal();
void RemoveSceneAsGlobal();
void LoadGlobalScenes();
void UpdatePinIcons();

public:
explicit OBSBasic(QWidget *parent = 0);
virtual ~OBSBasic();
Expand Down