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

Bugfix/load order #81

Merged
merged 3 commits into from
Oct 7, 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
18 changes: 9 additions & 9 deletions src/quick-access-dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ void QuickAccessDock::DrawDock(obs_data_t *obsData)

const auto d = static_cast<QDockWidget *>(parentWidget());

const auto floating = obs_data_get_bool(obsData, "dock_floating");
if (d->isFloating() != floating) {
d->setFloating(floating);
if (obs_data_get_bool(obsData, "dock_hidden")) {
d->hide();
} else {
d->show();
}

const auto area = static_cast<Qt::DockWidgetArea>(
Expand All @@ -244,17 +245,16 @@ void QuickAccessDock::DrawDock(obs_data_t *obsData)
mainWindow->addDockWidget(area, d);
}

const auto floating = obs_data_get_bool(obsData, "dock_floating");
if (d->isFloating() != floating) {
d->setFloating(floating);
}

const char *geometry = obs_data_get_string(obsData, "dock_geometry");
if (geometry && strlen(geometry)) {
d->restoreGeometry(
QByteArray::fromBase64(QByteArray(geometry)));
}

if (obs_data_get_bool(obsData, "dock_hidden")) {
d->hide();
} else {
d->show();
}
}

void QuickAccessDock::Save(obs_data_t *obsData)
Expand Down
1 change: 0 additions & 1 deletion src/quick-access-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ QuickAccessSource::QuickAccessSource(obs_source_t *source)
_sourceClass = obs_source_is_group(source) ? SourceClass::Group
: obs_source_is_scene(source) ? SourceClass::Scene
: SourceClass::Source;
blog(LOG_INFO, "====== Grabbed %s", _tmpName.c_str());
BuildSearchTerms();
}

Expand Down
70 changes: 47 additions & 23 deletions src/quick-access-utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ QuickAccessSearchModal *QuickAccessSearchModal::dialog = nullptr;
QuickAccessUtility::QuickAccessUtility(obs_module_t *m)
: _module(m),
_firstRun(false),
_currentScene(nullptr)
_currentScene(nullptr),
_dockSettings(nullptr)
{
obs_frontend_add_event_callback(QuickAccessUtility::FrontendCallback,
this);
Expand All @@ -53,6 +54,9 @@ void QuickAccessUtility::SourceCreated(void *data, calldata_t *params)
UNUSED_PARAMETER(data);
obs_source_t *source =
static_cast<obs_source_t *>(calldata_ptr(params, "source"));
if (obs_obj_is_private(source)) {
return;
}
std::string uuid = obs_source_get_uuid(source);
QuickAccessUtility::AddSource(nullptr, source);
if (qau->_allSources.count(uuid) == 0) {
Expand Down Expand Up @@ -167,15 +171,7 @@ void QuickAccessUtility::Load(obs_data_t *data)
std::unique_lock lock(_m);
RemoveDocks();
_allSources.clear();
// Add Scenes and sources to _allSources
obs_enum_all_sources(QuickAccessUtility::AddSource, qau);
obs_enum_scenes(QuickAccessUtility::AddSource, qau);

// Link scenes/groups with their children
obs_enum_scenes(QuickAccessUtility::LinkScenes, qau);

const auto mainWindow =
static_cast<QMainWindow *>(obs_frontend_get_main_window());
auto qauData = obs_data_get_obj(data, "quick_access_utility");
if (!qauData) {
qauData = obs_data_create();
Expand All @@ -185,14 +181,9 @@ void QuickAccessUtility::Load(obs_data_t *data)
obs_data_array_release(docks);
}
_firstRun = obs_data_get_bool(qauData, "first_run");
auto docks = obs_data_get_array(qauData, "docks");
for (size_t i = 0; i < obs_data_array_count(docks); i++) {
auto dockData = obs_data_array_item(docks, i);
auto d = new QuickAccessDock(mainWindow, dockData);
_docks.push_back(d);
obs_data_release(dockData);
}
obs_data_array_release(docks);
_dockSettings = obs_data_get_array(qauData, "docks");

_SetupDocks();

auto quickSearchHotkey =
obs_data_get_array(qauData, "quick_search_hotkey");
Expand All @@ -201,18 +192,40 @@ void QuickAccessUtility::Load(obs_data_t *data)

obs_data_release(qauData);

//loaded = true;
}

void QuickAccessUtility::_SetupDocks()
{
//std::unique_lock lock(_m);

// Add Scenes and sources to _allSources
obs_enum_all_sources(QuickAccessUtility::AddSource, qau);
obs_enum_scenes(QuickAccessUtility::AddSource, qau);

// Link scenes/groups with their children
obs_enum_scenes(QuickAccessUtility::LinkScenes, qau);

const auto mainWindow =
static_cast<QMainWindow *>(obs_frontend_get_main_window());

for (size_t i = 0; i < obs_data_array_count(_dockSettings); i++) {
auto dockData = obs_data_array_item(_dockSettings, i);
auto d = new QuickAccessDock(mainWindow, dockData);
_docks.push_back(d);
obs_data_release(dockData);
}
obs_data_array_release(_dockSettings);

// Set up the quick search dialog
// This shouldn't need to be done, but for some reason
// the first time we pop open the search, it is a tiny
// window and then disappears.
if (!QuickAccessSearchModal::dialog) {
const auto main_window = static_cast<QMainWindow *>(
obs_frontend_get_main_window());
const QRect &hostRect = main_window->geometry();
const QRect &hostRect = mainWindow->geometry();

QuickAccessSearchModal::dialog =
new QuickAccessSearchModal(static_cast<QMainWindow *>(
obs_frontend_get_main_window()));
new QuickAccessSearchModal(mainWindow);
auto searchDlg = QuickAccessSearchModal::dialog;
searchDlg->open();
searchDlg->move(hostRect.center() - searchDlg->rect().center());
Expand Down Expand Up @@ -348,7 +361,10 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event,
{
UNUSED_PARAMETER(data);
if (event == OBS_FRONTEND_EVENT_FINISHED_LOADING) {
blog(LOG_INFO,
"======== OBS_FRONTEND_EVENT_FINISHED_LOADING called.");
qau->_sceneCollectionChanging = false;
//qau->_SetupDocks();
qau->_SetupSignals();
qau->SceneChanged();
} else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP) {
Expand All @@ -361,7 +377,10 @@ void QuickAccessUtility::FrontendCallback(enum obs_frontend_event event,
qau->_TearDownSignals();
qau->_sceneCollectionChanging = true;
} else if (event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) {
blog(LOG_INFO,
"======== OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED called.");
qau->_sceneCollectionChanging = false;
//qau->_SetupDocks();
qau->_SetupSignals();
qau->InitializeSearch();
qau->SceneChanged();
Expand Down Expand Up @@ -579,11 +598,15 @@ bool QuickAccessUtility::AddSource(void *data, obs_source_t *source)
{
UNUSED_PARAMETER(data);

bool priv = obs_obj_is_private(source);
obs_source_type st = obs_source_get_type(source);
if (st == OBS_SOURCE_TYPE_FILTER || st == OBS_SOURCE_TYPE_TRANSITION) {
if (priv || st == OBS_SOURCE_TYPE_FILTER ||
st == OBS_SOURCE_TYPE_TRANSITION) {
return true;
}

std::string uuid = obs_source_get_uuid(source);

if (qau->_allSources.find(uuid) == qau->_allSources.end()) {
qau->_allSources.emplace(
uuid, std::make_unique<QuickAccessSource>(source));
Expand Down Expand Up @@ -1117,6 +1140,7 @@ extern "C" EXPORT void CheckModules()

void frontendSaveLoad(obs_data_t *save_data, bool saving, void *data)
{
blog(LOG_INFO, "======== obs_frontend_save_load_callback called.");
auto quickAccessUtility = static_cast<QuickAccessUtility *>(data);
if (saving) {
quickAccessUtility->Save(save_data);
Expand Down
2 changes: 2 additions & 0 deletions src/quick-access-utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class QuickAccessUtility {
void _TearDownSignals();
void _SetCurrentSceneSources();
void _AddChildren(QuickAccessSource *scene);
void _SetupDocks();

obs_module_t *_module = nullptr;
std::vector<QuickAccessDock *> _docks;
Expand All @@ -103,6 +104,7 @@ class QuickAccessUtility {
bool _sceneCollectionChanging = true;
bool _sourceCloneInstalled = false;
bool _dskInstalled = false;
obs_data_array_t *_dockSettings;

obs_hotkey_id _quick_search_hotkey_id;

Expand Down