Skip to content

Commit

Permalink
Stop using deprecated obs_frontend_add_dock()
Browse files Browse the repository at this point in the history
OBS Studio 30.0.0 deprecated the obs_frontend_add_dock() function and
advised plugins to use obs_frontend_add_dock_by_id() instead. However,
the new API takes the contents of the dock widget as an argument instead
of the dock widget itself, which requires rework of the widget
structure.

This commit removes the QDockWidget instance from the .ui file and
changes the PTZControls class to inheret from QWidget instead of
QDockWidget. It then reworks the instantiation to use the new API when
building against obs-studio 30.0.0 or higher. When building against
older versions it will create the needed QDockWidget before calling the
old API.

Fixes: #186
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
  • Loading branch information
glikely committed Mar 1, 2024
1 parent cc2b689 commit 195fb41
Show file tree
Hide file tree
Showing 3 changed files with 584 additions and 589 deletions.
23 changes: 19 additions & 4 deletions src/ptz-controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QToolTip>
#include <QWindow>
#include <QResizeEvent>
#include <QDockWidget>

#include "imported/qt-wrappers.hpp"
#include "imported/qjoysticks/QJoysticks.h"
Expand All @@ -29,9 +30,23 @@ void ptz_load_controls(void)
const auto main_window =
static_cast<QMainWindow *>(obs_frontend_get_main_window());
obs_frontend_push_ui_translation(obs_module_get_string);
auto *tmp = new PTZControls(main_window);
obs_frontend_add_dock(tmp);
tmp->setFloating(true); // Do after add_dock() to keep hidden at startup
auto *ctrls = new PTZControls(main_window);

#if LIBOBS_API_VER >= MAKE_SEMANTIC_VERSION(30, 0, 0)
if (!obs_frontend_add_dock_by_id("ptz-dock", "PTZ Controls", ctrls))
blog(LOG_ERROR, "failed to add PTZ controls dock");
#else
auto dock = new QDockWidget(main_window);
dock->setObjectName("ptz-dock");
dock->setWindowTitle("PTZ Controls");
dock->setWidget(ctrls);
dock->setFeatures(QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable);
dock->setFloating(true);
dock->hide();
obs_frontend_add_dock(dock);
#endif

obs_frontend_pop_ui_translation();
}

Expand Down Expand Up @@ -121,7 +136,7 @@ void PTZControls::OBSFrontendEvent(enum obs_frontend_event event)
}

PTZControls::PTZControls(QWidget *parent)
: QDockWidget(parent), ui(new Ui::PTZControls)
: QWidget(parent), ui(new Ui::PTZControls)
{
instance = this;
ui->setupUi(this);
Expand Down
3 changes: 1 addition & 2 deletions src/ptz-controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
#include "ptz.h"
#include <QTimer>
#include <obs.hpp>
#include <QDockWidget>
#include "imported/qjoysticks/QJoysticks.h"
#include "touch-control.hpp"
#include "ptz-device.hpp"
#include "ui_ptz-controls.h"

class PTZControls : public QDockWidget {
class PTZControls : public QWidget {
Q_OBJECT

private:
Expand Down
Loading

0 comments on commit 195fb41

Please sign in to comment.