Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
exeldro committed Nov 28, 2024
1 parent 811e57e commit ad05c2f
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 490 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ else()
endif()

if(BUILD_OUT_OF_TREE)
find_qt(COMPONENTS Widgets Core)
find_qt(COMPONENTS Widgets Core COMPONENTS_LINUX Gui)
else()
find_package(Qt6 REQUIRED COMPONENTS Core Widgets)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Core Qt::Widgets)

if(OS_MACOS)
elseif(OS_POSIX)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt::GuiPrivate)
endif()

target_compile_options(
${PROJECT_NAME} PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header
-Wno-comma>)
Expand Down
39 changes: 15 additions & 24 deletions config-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,8 @@ OBSBasicSettings::OBSBasicSettings(CanvasDock *canvas_dock, QMainWindow *parent)
}
QMetaObject::invokeMethod(streamingUseMain, "stateChanged", Q_ARG(int, streamingUseMain->checkState()));
});
streamingAdvancedLayout->addRow(
QString::fromUtf8(obs_frontend_get_locale_string(
(obs_get_version() >= MAKE_SEMANTIC_VERSION(29, 1, 0) || strncmp(obs_get_version_string(), "29.1.", 5) == 0)
? "Basic.Settings.Output.Encoder.Video"
: "Basic.Settings.Output.Encoder")),
streamingEncoder);
streamingAdvancedLayout->addRow(QString::fromUtf8(obs_frontend_get_locale_string("Basic.Settings.Output.Encoder.Video")),
streamingEncoder);
QMetaObject::invokeMethod(streamingEncoder, "currentIndexChanged", Q_ARG(int, streamingEncoder->currentIndex()));

streamingAdvancedGroup->setLayout(streamingAdvancedLayout);
Expand Down Expand Up @@ -853,12 +849,8 @@ OBSBasicSettings::OBSBasicSettings(CanvasDock *canvas_dock, QMainWindow *parent)
QMetaObject::invokeMethod(recordingUseMain, "stateChanged", Q_ARG(int, recordingUseMain->checkState()));
});

recordingAdvancedLayout->addRow(
QString::fromUtf8(obs_frontend_get_locale_string(
(obs_get_version() >= MAKE_SEMANTIC_VERSION(29, 1, 0) || strncmp(obs_get_version_string(), "29.1.", 5) == 0)
? "Basic.Settings.Output.Encoder.Video"
: "Basic.Settings.Output.Encoder")),
recordingEncoder);
recordingAdvancedLayout->addRow(QString::fromUtf8(obs_frontend_get_locale_string("Basic.Settings.Output.Encoder.Video")),
recordingEncoder);

recordingAdvancedGroup->setLayout(recordingAdvancedLayout);

Expand Down Expand Up @@ -1474,11 +1466,10 @@ std::vector<obs_hotkey_t *> OBSBasicSettings::GetHotKeysFromOutput(obs_output_t
find_hotkey t = {};
t.output = obs_output_get_weak_output(output);
obs_enum_hotkeys(
[](void *data, obs_hotkey_id id, obs_hotkey_t *key) {
UNUSED_PARAMETER(id);
[](void *param, obs_hotkey_id, obs_hotkey_t *key) {
if (obs_hotkey_get_registerer_type(key) != OBS_HOTKEY_REGISTERER_OUTPUT)
return true;
auto hp = (struct find_hotkey *)data;
auto hp = (struct find_hotkey *)param;
auto o = obs_hotkey_get_registerer(key);
if (o == hp->output || obs_weak_output_references_output(hp->output, (obs_output_t *)o)) {
hp->hotkeys.push_back(key);
Expand All @@ -1498,11 +1489,11 @@ std::vector<obs_key_combination_t> OBSBasicSettings::GetCombosForHotkey(obs_hotk
};
find_combos t = {hotkey, {}};
obs_enum_hotkey_bindings(
[](void *data, size_t idx, obs_hotkey_binding_t *binding) {
[](void *param, size_t idx, obs_hotkey_binding_t *binding) {
UNUSED_PARAMETER(idx);
auto t = (struct find_combos *)data;
if (t->hotkey == obs_hotkey_binding_get_hotkey_id(binding)) {
t->combos.push_back(obs_hotkey_binding_get_key_combination(binding));
auto fc = (struct find_combos *)param;
if (fc->hotkey == obs_hotkey_binding_get_hotkey_id(binding)) {
fc->combos.push_back(obs_hotkey_binding_get_key_combination(binding));
}
return true;
},
Expand All @@ -1519,8 +1510,8 @@ std::vector<obs_hotkey_t *> OBSBasicSettings::GetHotkeyById(obs_hotkey_id hotkey
find_hotkey t = {};
t.hotkey_id = hotkey;
obs_enum_hotkeys(
[](void *data, obs_hotkey_id id, obs_hotkey_t *key) {
auto hp = (struct find_hotkey *)data;
[](void *param, obs_hotkey_id id, obs_hotkey_t *key) {
auto hp = (struct find_hotkey *)param;
if (hp->hotkey_id == id) {
hp->hotkeys.push_back(key);
}
Expand All @@ -1540,9 +1531,9 @@ obs_hotkey_t *OBSBasicSettings::GetHotkeyByName(QString name)
auto n = name.toUtf8();
t.name = n.constData();
obs_enum_hotkeys(
[](void *data, obs_hotkey_id id, obs_hotkey_t *key) {
[](void *param, obs_hotkey_id id, obs_hotkey_t *key) {
UNUSED_PARAMETER(id);
const auto hp = (struct find_hotkey *)data;
const auto hp = (struct find_hotkey *)param;
const auto hn = obs_hotkey_get_name(key);
if (strcmp(hp->name, hn) == 0)
hp->hotkey = key;
Expand Down Expand Up @@ -1807,7 +1798,7 @@ void OBSBasicSettings::LoadProperty(obs_property_t *prop, obs_data_t *settings,
if (type == OBS_PROPERTY_BOOL) {
((QCheckBox *)widget)->setChecked(obs_data_get_bool(settings, obs_property_name(prop)));
} else if (type == OBS_PROPERTY_INT) {
((QSpinBox *)widget)->setValue(obs_data_get_int(settings, obs_property_name(prop)));
((QSpinBox *)widget)->setValue((int)obs_data_get_int(settings, obs_property_name(prop)));
} else if (type == OBS_PROPERTY_FLOAT) {
((QDoubleSpinBox *)widget)->setValue(obs_data_get_double(settings, obs_property_name(prop)));
} else if (type == OBS_PROPERTY_TEXT) {
Expand Down
8 changes: 4 additions & 4 deletions display-helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ static inline void GetScaleAndCenterPos(int baseCX, int baseCY, int windowCX, in

static inline void GetCenterPosFromFixedScale(int baseCX, int baseCY, int windowCX, int windowCY, int &x, int &y, float scale)
{
x = (float(windowCX) - float(baseCX) * scale) / 2.0f;
y = (float(windowCY) - float(baseCY) * scale) / 2.0f;
x = (int)((float(windowCX) - float(baseCX) * scale) / 2.0f);
y = (int)((float(windowCY) - float(baseCY) * scale) / 2.0f);
}

static inline QSize GetPixelSize(QWidget *widget)
Expand Down Expand Up @@ -119,8 +119,8 @@ static inline void RenderSafeAreas(gs_vertbuffer_t *vb, int cx, int cy)

matrix4 transform;
matrix4_identity(&transform);
transform.x.x = cx;
transform.y.y = cy;
transform.x.x = (float)cx;
transform.y.y = (float)cy;

gs_load_vertexbuffer(vb);

Expand Down
10 changes: 5 additions & 5 deletions hotkey-edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void OBSHotkeyWidget::AddEdit(obs_key_combination combo, int idx)
return std::distance(begin(removeButtons), res);
};

QObject::connect(add, &QPushButton::clicked, [&, CurrentIndex] { AddEdit({0, OBS_KEY_NONE}, CurrentIndex() + 1); });
QObject::connect(add, &QPushButton::clicked, [&, CurrentIndex] { AddEdit({0, OBS_KEY_NONE}, (int)CurrentIndex() + 1); });

QObject::connect(remove, &QPushButton::clicked, [&, CurrentIndex] { RemoveEdit(CurrentIndex()); });

Expand Down Expand Up @@ -361,7 +361,7 @@ void OBSHotkeyWidget::AddEdit(obs_key_combination combo, int idx)
QObject::connect(clear, &QPushButton::clicked, edit, &OBSHotkeyEdit::ClearKey);

QObject::connect(edit, &OBSHotkeyEdit::KeyChanged, [&](obs_key_combination) { emit KeyChanged(); });
QObject::connect(edit, &OBSHotkeyEdit::SearchKey, [=](obs_key_combination combo) { emit SearchKey(combo); });
QObject::connect(edit, &OBSHotkeyEdit::SearchKey, [=](obs_key_combination c) { emit SearchKey(c); });
}

void OBSHotkeyWidget::RemoveEdit(size_t idx, bool signal)
Expand Down Expand Up @@ -413,9 +413,9 @@ void OBSHotkeyWidget::HandleChangedBindings(obs_hotkey_id id_)
using LoadBindings_t = decltype(&LoadBindings);

obs_enum_hotkey_bindings(
[](void *data, size_t, obs_hotkey_binding_t *binding) {
auto LoadBindings = *static_cast<LoadBindings_t>(data);
LoadBindings(binding);
[](void *param, size_t, obs_hotkey_binding_t *binding) {
auto LoadBindingsFunc = *static_cast<LoadBindings_t>(param);
LoadBindingsFunc(binding);
return true;
},
static_cast<void *>(&LoadBindings));
Expand Down
20 changes: 4 additions & 16 deletions hotkey-edit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class OBSHotkeyEdit : public QLineEdit {
Q_OBJECT;

public:
OBSHotkeyEdit(QWidget *parent, obs_key_combination_t original) : QLineEdit(parent), original(original)
OBSHotkeyEdit(QWidget *parent, obs_key_combination_t original_) : QLineEdit(parent), original(original_)
{
#ifdef __APPLE__
// disable the input cursor on OSX, focus should be clear
Expand All @@ -72,18 +72,6 @@ class OBSHotkeyEdit : public QLineEdit {
CreateDupeIcon();
ResetKey();
}
OBSHotkeyEdit(QWidget *parent = nullptr) : QLineEdit(parent), original({})
{
#ifdef __APPLE__
// disable the input cursor on OSX, focus should be clear
// enough with the default focus frame
setReadOnly(true);
#endif
setAttribute(Qt::WA_InputMethodEnabled, false);
setAttribute(Qt::WA_MacShowFocusRect, true);
InitSignalHandler();
ResetKey();
}

obs_key_combination_t original;
obs_key_combination_t key;
Expand Down Expand Up @@ -123,10 +111,10 @@ class OBSHotkeyWidget : public QWidget {
Q_OBJECT;

public:
OBSHotkeyWidget(QWidget *parent, obs_hotkey_id id, std::string name, const std::vector<obs_key_combination_t> &combos = {})
OBSHotkeyWidget(QWidget *parent, obs_hotkey_id id_, std::string name_, const std::vector<obs_key_combination_t> &combos = {})
: QWidget(parent),
id(id),
name(name),
id(id_),
name(name_),
bindingsChanged(obs_get_signal_handler(), "hotkey_bindings_changed", &OBSHotkeyWidget::BindingsChanged, this)
{
auto layout = new QVBoxLayout;
Expand Down
12 changes: 6 additions & 6 deletions projector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ void OBSProjector::ResizeToContent()
resize(newX, newY);
}

void OBSProjector::AlwaysOnTopToggled(bool isAlwaysOnTop)
void OBSProjector::AlwaysOnTopToggled(bool onTop)
{
SetIsAlwaysOnTop(isAlwaysOnTop, true);
SetIsAlwaysOnTop(onTop, true);
}

void OBSProjector::closeEvent(QCloseEvent *event)
Expand All @@ -297,12 +297,12 @@ bool OBSProjector::IsAlwaysOnTopOverridden() const
return isAlwaysOnTopOverridden;
}

void OBSProjector::SetIsAlwaysOnTop(bool isAlwaysOnTop, bool isOverridden)
void OBSProjector::SetIsAlwaysOnTop(bool onTop, bool isOverridden)
{
this->isAlwaysOnTop = isAlwaysOnTop;
this->isAlwaysOnTopOverridden = isOverridden;
isAlwaysOnTop = onTop;
isAlwaysOnTopOverridden = isOverridden;

SetAlwaysOnTop(this, isAlwaysOnTop);
SetAlwaysOnTop(this, onTop);
}

void OBSProjector::ScreenRemoved(QScreen *screen_)
Expand Down
15 changes: 9 additions & 6 deletions qt-display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
#include <Windows.h>
#endif

#ifdef ENABLE_WAYLAND
#if !defined(_WIN32) && !defined(__APPLE__)
#include <obs-nix-platform.h>
#include <qpa/qplatformnativeinterface.h>
#endif

#ifdef ENABLE_WAYLAND
#include <QGuiApplication>
#include <qpa/qplatformnativeinterface.h>
#endif

class SurfaceEventFilter : public QObject {
OBSQTDisplay *display;
Expand Down Expand Up @@ -72,12 +76,11 @@ class SurfaceEventFilter : public QObject {
}
};

#endif

static inline long long color_to_int(const QColor &color)
{
auto shift = [&](unsigned val, int shift) {
return ((val & 0xff) << shift);
auto shift = [&](unsigned val, int shift_left) {
return ((val & 0xff) << shift_left);
};

return shift(color.red(), 0) | shift(color.green(), 8) | shift(color.blue(), 16) | shift(color.alpha(), 24);
Expand Down Expand Up @@ -159,7 +162,7 @@ bool QTToGSWindow(QWindow *window, gs_window &gswindow)
gswindow.view = (id)window->winId();
#else
if (obs_get_nix_platform() == OBS_NIX_PLATFORM_X11_EGL) {
gswindow.id = window->winId();
gswindow.id = (uint32_t)window->winId();
gswindow.display = obs_get_nix_platform_display();
}
#ifdef ENABLE_WAYLAND
Expand Down
50 changes: 25 additions & 25 deletions scenes-dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ bool CanvasScenesDock::IsGridMode()
return sceneList->viewMode() == QListView::IconMode;
}

void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *item)
void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *widget_item)
{
auto menu = QMenu(this);
auto a = menu.addAction(QString::fromUtf8(obs_frontend_get_locale_string("Basic.Main.GridMode")),
[this](bool checked) { SetGridMode(checked); });
a->setCheckable(true);
a->setChecked(IsGridMode());
menu.addAction(QString::fromUtf8(obs_frontend_get_locale_string("Add")), [this] { canvasDock->AddScene(); });
if (!item) {
if (!widget_item) {
menu.exec(QCursor::pos());
return;
}
menu.addSeparator();
menu.addAction(QString::fromUtf8(obs_frontend_get_locale_string("Duplicate")), [this] {
const auto item = sceneList->currentItem();
auto item = sceneList->currentItem();
if (!item)
return;
canvasDock->AddScene(item->text());
Expand Down Expand Up @@ -107,12 +107,12 @@ void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *item)
});

auto tom = menu.addMenu(QString::fromUtf8(obs_frontend_get_locale_string("TransitionOverride")));
std::string scene_name = item->text().toUtf8().constData();
std::string scene_name = widget_item->text().toUtf8().constData();
OBSSourceAutoRelease scene_source = obs_get_source_by_name(scene_name.c_str());
OBSDataAutoRelease data = obs_source_get_private_settings(scene_source);
obs_data_set_default_int(data, "transition_duration", 300);
const char *curTransition = obs_data_get_string(data, "transition");
int curDuration = (int)obs_data_get_int(data, "transition_duration");
OBSDataAutoRelease private_settings = obs_source_get_private_settings(scene_source);
obs_data_set_default_int(private_settings, "transition_duration", 300);
const char *curTransition = obs_data_get_string(private_settings, "transition");
int curDuration = (int)obs_data_get_int(private_settings, "transition_duration");

QSpinBox *duration = new QSpinBox(tom);
duration->setMinimum(50);
Expand All @@ -121,20 +121,20 @@ void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *item)
duration->setSingleStep(50);
duration->setValue(curDuration);

connect(duration, (void(QSpinBox::*)(int)) & QSpinBox::valueChanged, [scene_name](int duration) {
connect(duration, (void(QSpinBox::*)(int)) & QSpinBox::valueChanged, [scene_name](int dur) {
OBSSourceAutoRelease source = obs_get_source_by_name(scene_name.c_str());
OBSDataAutoRelease data = obs_source_get_private_settings(source);
OBSDataAutoRelease ps = obs_source_get_private_settings(source);

obs_data_set_int(data, "transition_duration", duration);
obs_data_set_int(ps, "transition_duration", dur);
});

auto action = tom->addAction(QString::fromUtf8(obs_frontend_get_locale_string("None")));
action->setCheckable(true);
action->setChecked(!curTransition || !strlen(curTransition));
connect(action, &QAction::triggered, [scene_name] {
OBSSourceAutoRelease source = obs_get_source_by_name(scene_name.c_str());
OBSDataAutoRelease data = obs_source_get_private_settings(source);
obs_data_set_string(data, "transition", "");
OBSDataAutoRelease ps = obs_source_get_private_settings(source);
obs_data_set_string(ps, "transition", "");
});

for (auto t : canvasDock->transitions) {
Expand All @@ -144,13 +144,13 @@ void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *item)
if (!name || !*name)
name = obs_frontend_get_locale_string("None");

auto action = tom->addAction(QString::fromUtf8(name));
action->setCheckable(true);
action->setChecked(match);
connect(action, &QAction::triggered, [scene_name, action] {
auto a2 = tom->addAction(QString::fromUtf8(name));
a2->setCheckable(true);
a2->setChecked(match);
connect(a, &QAction::triggered, [scene_name, a2] {
OBSSourceAutoRelease source = obs_get_source_by_name(scene_name.c_str());
OBSDataAutoRelease data = obs_source_get_private_settings(source);
obs_data_set_string(data, "transition", action->text().toUtf8().constData());
OBSDataAutoRelease ps = obs_source_get_private_settings(source);
obs_data_set_string(ps, "transition", a2->text().toUtf8().constData());
});
}

Expand Down Expand Up @@ -187,8 +187,8 @@ void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *item)
if (c) {
const auto count = obs_data_array_count(c);

for (size_t i = 0; i < count; i++) {
auto item = obs_data_array_item(c, i);
for (size_t j = 0; j < count; j++) {
auto item = obs_data_array_item(c, j);
if (!item)
continue;
if (obs_data_get_int(item, "width") == canvasDock->canvas_width &&
Expand Down Expand Up @@ -226,12 +226,12 @@ void CanvasScenesDock::ShowScenesContextMenu(QListWidgetItem *item)
}
a = menu.addAction(QString::fromUtf8(obs_frontend_get_locale_string("ShowInMultiview")), [scene_name](bool checked) {
OBSSourceAutoRelease source = obs_get_source_by_name(scene_name.c_str());
OBSDataAutoRelease data = obs_source_get_private_settings(source);
obs_data_set_bool(data, "show_in_multiview", checked);
OBSDataAutoRelease ps = obs_source_get_private_settings(source);
obs_data_set_bool(ps, "show_in_multiview", checked);
});
a->setCheckable(true);
obs_data_set_default_bool(data, "show_in_multiview", true);
a->setChecked(obs_data_get_bool(data, "show_in_multiview"));
obs_data_set_default_bool(private_settings, "show_in_multiview", true);
a->setChecked(obs_data_get_bool(private_settings, "show_in_multiview"));
menu.exec(QCursor::pos());
}

Expand Down
Loading

0 comments on commit ad05c2f

Please sign in to comment.