Skip to content

Commit f0efedf

Browse files
committed
Draft source interaction action
1 parent a901f59 commit f0efedf

File tree

6 files changed

+1351
-36
lines changed

6 files changed

+1351
-36
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ target_sources(
262262
src/utils/screenshot-helper.hpp
263263
src/utils/section.cpp
264264
src/utils/section.hpp
265+
src/utils/source-interact.cpp
266+
src/utils/source-interact.hpp
265267
src/utils/transition-selection.cpp
266268
src/utils/transition-selection.hpp
267269
src/utils/utility.cpp

data/locale/en-US.ini

+28
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ AdvSceneSwitcher.action.source.type.refreshSettings="Refresh source settings"
445445
AdvSceneSwitcher.action.source.type.pressSettingsButton="Press settings button"
446446
AdvSceneSwitcher.action.source.type.refreshSettings.tooltip="Can be used to refresh browser, media, etc. sources"
447447
AdvSceneSwitcher.action.source.noSettingsButtons="No buttons found!"
448+
AdvSceneSwitcher.action.source.type.interact="Interact"
449+
AdvSceneSwitcher.action.source.type.interact.selectType="Interaction type:{{type}}"
450+
AdvSceneSwitcher.action.source.type.interact.mouseClick="Send mouse click"
451+
AdvSceneSwitcher.action.source.type.interact.mouseMove="Send mouse move"
452+
AdvSceneSwitcher.action.source.type.interact.mouseWheel="Send mouse wheel"
453+
AdvSceneSwitcher.action.source.type.interact.keyPress="Send key press"
448454
AdvSceneSwitcher.action.source.entry="{{actions}}{{sources}}{{settingsButtons}}"
449455
AdvSceneSwitcher.action.source.warning="Warning: Enabling and disabling sources globally cannot be controlled by the OBS UI"
450456
AdvSceneSwitcher.action.source.getSettings="Get current settings"
@@ -900,6 +906,28 @@ AdvSceneSwitcher.duration.condition.equal="For exactly"
900906
AdvSceneSwitcher.duration.condition.less="For at most"
901907
AdvSceneSwitcher.duration.condition.within="Within the last"
902908

909+
<<<<<<< HEAD
903910
AdvSceneSwitcher.audio.monitor.none="Monitor Off"
904911
AdvSceneSwitcher.audio.monitor.monitorOnly="Monitor Only (mute output)"
905912
AdvSceneSwitcher.audio.monitor.both="Monitor and Output"
913+
=======
914+
AdvSceneSwitcher.key="Key:"
915+
AdvSceneSwitcher.key.up="Key up:"
916+
AdvSceneSwitcher.key.pressCount="Key press count:"
917+
918+
AdvSceneSwitcher.modifierKey="Modifier keys:"
919+
AdvSceneSwitcher.modifierKey.shift="Shift"
920+
AdvSceneSwitcher.modifierKey.ctrl="Ctrl"
921+
AdvSceneSwitcher.modifierKey.alt="Alt"
922+
AdvSceneSwitcher.modifierKey.meta="Meta"
923+
924+
AdvSceneSwitcher.mouse.button="Mouse button:"
925+
AdvSceneSwitcher.mouse.button.left="Left"
926+
AdvSceneSwitcher.mouse.button.middle="Middle"
927+
AdvSceneSwitcher.mouse.button.right="Right"
928+
AdvSceneSwitcher.mouse.position="Mouse position:"
929+
AdvSceneSwitcher.mouse.up="Mouse up event:"
930+
AdvSceneSwitcher.mouse.count="Mouse click count:"
931+
AdvSceneSwitcher.mouse.leave="Mouse leave event:"
932+
AdvSceneSwitcher.mouse.scrollAmount="Mouse scroll amount:"
933+
>>>>>>> 06334ae (Draft source interaction action)

src/macro-core/macro-action-source.cpp

+71-27
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ bool MacroActionSource::_registered = MacroActionFactory::Register(
1111
{MacroActionSource::Create, MacroActionSourceEdit::Create,
1212
"AdvSceneSwitcher.action.source"});
1313

14-
const static std::map<SourceAction, std::string> actionTypes = {
15-
{SourceAction::ENABLE, "AdvSceneSwitcher.action.source.type.enable"},
16-
{SourceAction::DISABLE, "AdvSceneSwitcher.action.source.type.disable"},
17-
{SourceAction::SETTINGS,
14+
const static std::map<MacroActionSource::Action, std::string> actionTypes = {
15+
{MacroActionSource::Action::ENABLE,
16+
"AdvSceneSwitcher.action.source.type.enable"},
17+
{MacroActionSource::Action::DISABLE,
18+
"AdvSceneSwitcher.action.source.type.disable"},
19+
{MacroActionSource::Action::SETTINGS,
1820
"AdvSceneSwitcher.action.source.type.settings"},
19-
{SourceAction::REFRESH_SETTINGS,
21+
{MacroActionSource::Action::REFRESH_SETTINGS,
2022
"AdvSceneSwitcher.action.source.type.refreshSettings"},
21-
{SourceAction::SETTINGS_BUTTON,
23+
{MacroActionSource::Action::SETTINGS_BUTTON,
2224
"AdvSceneSwitcher.action.source.type.pressSettingsButton"},
25+
{MacroActionSource::Action::INTERACT,
26+
"AdvSceneSwitcher.action.source.type.interact"},
2327
};
2428

2529
static std::vector<SourceSettingButton> getSourceButtons(OBSWeakSource source)
@@ -78,20 +82,22 @@ bool MacroActionSource::PerformAction()
7882
{
7983
auto s = obs_weak_source_get_source(_source);
8084
switch (_action) {
81-
case SourceAction::ENABLE:
85+
case Action::ENABLE:
8286
obs_source_set_enabled(s, true);
8387
break;
84-
case SourceAction::DISABLE:
88+
case Action::DISABLE:
8589
obs_source_set_enabled(s, false);
8690
break;
87-
case SourceAction::SETTINGS:
91+
case Action::SETTINGS:
8892
setSourceSettings(s, _settings);
8993
break;
90-
case SourceAction::REFRESH_SETTINGS:
94+
case Action::REFRESH_SETTINGS:
9195
refreshSourceSettings(s);
9296
break;
93-
case SourceAction::SETTINGS_BUTTON:
97+
case Action::SETTINGS_BUTTON:
9498
pressSourceButton(_button, s);
99+
case Action::INTERACT:
100+
_interaction.SendToSource(s);
95101
break;
96102
default:
97103
break;
@@ -119,6 +125,7 @@ bool MacroActionSource::Save(obs_data_t *obj)
119125
obs_data_set_int(obj, "action", static_cast<int>(_action));
120126
obs_data_set_string(obj, "settings", _settings.c_str());
121127
_button.Save(obj);
128+
_interaction.Save(obj);
122129
return true;
123130
}
124131

@@ -127,9 +134,11 @@ bool MacroActionSource::Load(obs_data_t *obj)
127134
MacroAction::Load(obj);
128135
const char *sourceName = obs_data_get_string(obj, "source");
129136
_source = GetWeakSourceByName(sourceName);
130-
_action = static_cast<SourceAction>(obs_data_get_int(obj, "action"));
137+
_action = static_cast<MacroActionSource::Action>(
138+
obs_data_get_int(obj, "action"));
131139
_settings = obs_data_get_string(obj, "settings");
132140
_button.Load(obj);
141+
_interaction.Load(obj);
133142
return true;
134143
}
135144

@@ -145,7 +154,7 @@ static inline void populateActionSelection(QComboBox *list)
145154
{
146155
for (auto &[actionType, name] : actionTypes) {
147156
list->addItem(obs_module_text(name.c_str()));
148-
if (actionType == SourceAction::REFRESH_SETTINGS) {
157+
if (actionType == MacroActionSource::Action::REFRESH_SETTINGS) {
149158
list->setItemData(
150159
list->count() - 1,
151160
obs_module_text(
@@ -174,17 +183,17 @@ static inline void populateSourceButtonSelection(QComboBox *list,
174183

175184
MacroActionSourceEdit::MacroActionSourceEdit(
176185
QWidget *parent, std::shared_ptr<MacroActionSource> entryData)
177-
: QWidget(parent)
186+
: QWidget(parent),
187+
_sources(new QComboBox),
188+
_actions(new QComboBox),
189+
_settingsButtons(new QComboBox),
190+
_getSettings(new QPushButton(obs_module_text(
191+
"AdvSceneSwitcher.action.source.getSettings"))),
192+
_settings(new ResizingPlainTextEdit(this)),
193+
_warning(new QLabel(
194+
obs_module_text("AdvSceneSwitcher.action.source.warning"))),
195+
_interaction(new SourceInteractionWidget())
178196
{
179-
_sources = new QComboBox();
180-
_actions = new QComboBox();
181-
_settingsButtons = new QComboBox();
182-
_getSettings = new QPushButton(
183-
obs_module_text("AdvSceneSwitcher.action.source.getSettings"));
184-
_settings = new ResizingPlainTextEdit(this);
185-
_warning = new QLabel(
186-
obs_module_text("AdvSceneSwitcher.action.source.warning"));
187-
188197
populateActionSelection(_actions);
189198
populateSourceSelection(_sources);
190199

@@ -198,6 +207,13 @@ MacroActionSourceEdit::MacroActionSourceEdit(
198207
SLOT(GetSettingsClicked()));
199208
QWidget::connect(_settings, SIGNAL(textChanged()), this,
200209
SLOT(SettingsChanged()));
210+
QWidget::connect(
211+
_interaction,
212+
SIGNAL(SettingsChanged(SourceInteractionInstance *)), this,
213+
SLOT(InteractionSettingsChanged(SourceInteractionInstance *)));
214+
QWidget::connect(_interaction,
215+
SIGNAL(TypeChanged(SourceInteraction::Type)), this,
216+
SLOT(InteractionTypeChanged(SourceInteraction::Type)));
201217

202218
QVBoxLayout *mainLayout = new QVBoxLayout;
203219
QHBoxLayout *entryLayout = new QHBoxLayout;
@@ -217,6 +233,7 @@ MacroActionSourceEdit::MacroActionSourceEdit(
217233
buttonLayout->addWidget(_getSettings);
218234
buttonLayout->addStretch();
219235
mainLayout->addLayout(buttonLayout);
236+
mainLayout->addWidget(_interaction);
220237
setLayout(mainLayout);
221238

222239
_entryData = entryData;
@@ -238,6 +255,7 @@ void MacroActionSourceEdit::UpdateEntryData()
238255
_settings->setPlainText(QString::fromStdString(_entryData->_settings));
239256
_settingsButtons->setCurrentText(
240257
QString::fromStdString(_entryData->_button.ToString()));
258+
_interaction->SetSourceInteractionSelection(_entryData->_interaction);
241259
SetWidgetVisibility();
242260

243261
adjustSize();
@@ -266,7 +284,7 @@ void MacroActionSourceEdit::ActionChanged(int value)
266284
}
267285

268286
std::lock_guard<std::mutex> lock(switcher->m);
269-
_entryData->_action = static_cast<SourceAction>(value);
287+
_entryData->_action = static_cast<MacroActionSource::Action>(value);
270288
SetWidgetVisibility();
271289
}
272290

@@ -299,22 +317,48 @@ void MacroActionSourceEdit::SettingsChanged()
299317

300318
std::lock_guard<std::mutex> lock(switcher->m);
301319
_entryData->_settings = _settings->toPlainText().toStdString();
320+
}
321+
322+
void MacroActionSourceEdit::InteractionTypeChanged(SourceInteraction::Type value)
323+
{
324+
if (_loading || !_entryData) {
325+
return;
326+
}
327+
328+
std::lock_guard<std::mutex> lock(switcher->m);
329+
_entryData->_interaction.SetType(value);
302330

303331
adjustSize();
304332
updateGeometry();
305333
}
306334

335+
void MacroActionSourceEdit::InteractionSettingsChanged(
336+
SourceInteractionInstance *value)
337+
{
338+
if (_loading || !_entryData) {
339+
return;
340+
}
341+
342+
std::lock_guard<std::mutex> lock(switcher->m);
343+
_entryData->_interaction.SetSettings(value);
344+
}
345+
307346
void MacroActionSourceEdit::SetWidgetVisibility()
308347
{
309-
const bool showSettings = _entryData->_action == SourceAction::SETTINGS;
310-
const bool showWarning = _entryData->_action == SourceAction::ENABLE ||
311-
_entryData->_action == SourceAction::DISABLE;
348+
const bool showSettings = _entryData->_action ==
349+
MacroActionSource::Action::SETTINGS;
350+
const bool showWarning =
351+
_entryData->_action == MacroActionSource::Action::ENABLE ||
352+
_entryData->_action == MacroActionSource::Action::DISABLE;
312353
_settings->setVisible(showSettings);
313354
_getSettings->setVisible(showSettings);
314355
_warning->setVisible(showWarning);
315356
_settingsButtons->setVisible(_entryData->_action ==
316357
SourceAction::SETTINGS_BUTTON);
358+
_interaction->setVisible(_entryData->_action ==
359+
MacroActionSource::Action::INTERACT);
317360
adjustSize();
361+
updateGeometry();
318362
}
319363

320364
bool SourceSettingButton::Save(obs_data_t *obj) const

src/macro-core/macro-action-source.hpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
#pragma once
22
#include "macro-action-edit.hpp"
33
#include "resizing-text-edit.hpp"
4+
#include "source-interact.hpp"
45

56
#include <QSpinBox>
67
#include <QLabel>
78
#include <QPushButton>
89
#include <QComboBox>
910

10-
enum class SourceAction {
11-
ENABLE,
12-
DISABLE,
13-
SETTINGS,
14-
REFRESH_SETTINGS,
15-
SETTINGS_BUTTON,
16-
};
17-
1811
struct SourceSettingButton {
1912
bool Save(obs_data_t *obj) const;
2013
bool Load(obs_data_t *obj);
@@ -38,10 +31,20 @@ class MacroActionSource : public MacroAction {
3831
return std::make_shared<MacroActionSource>(m);
3932
}
4033

34+
enum class Action {
35+
ENABLE,
36+
DISABLE,
37+
SETTINGS,
38+
REFRESH_SETTINGS,
39+
SETTINGS_BUTTON,
40+
INTERACT,
41+
};
42+
4143
OBSWeakSource _source;
4244
std::string _settings = "";
4345
SourceSettingButton _button;
44-
SourceAction _action = SourceAction::ENABLE;
46+
SourceInteraction _interaction;
47+
Action _action = Action::ENABLE;
4548

4649
private:
4750
static bool _registered;
@@ -70,6 +73,8 @@ private slots:
7073
void ButtonChanged(int idx);
7174
void GetSettingsClicked();
7275
void SettingsChanged();
76+
void InteractionTypeChanged(SourceInteraction::Type value);
77+
void InteractionSettingsChanged(SourceInteractionInstance *value);
7378
signals:
7479
void HeaderInfoChanged(const QString &);
7580

@@ -80,6 +85,8 @@ private slots:
8085
QPushButton *_getSettings;
8186
ResizingPlainTextEdit *_settings;
8287
QLabel *_warning;
88+
SourceInteractionWidget *_interaction;
89+
8390
std::shared_ptr<MacroActionSource> _entryData;
8491

8592
private:

0 commit comments

Comments
 (0)