mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-04-22 18:17:25 -05:00
Add ability to choose focus state to window title switcher
This commit is contained in:
parent
a4de8c0c59
commit
e4b640903d
|
|
@ -159,7 +159,7 @@ SceneSwitcher::SceneSwitcher(QWidget *parent)
|
|||
string transitionName = GetWeakSourceName(s.transition);
|
||||
QString text =
|
||||
MakeSwitchName(sceneName.c_str(), s.window.c_str(),
|
||||
transitionName.c_str(), s.fullscreen);
|
||||
transitionName.c_str(), s.fullscreen, s.focus);
|
||||
|
||||
QListWidgetItem *item = new QListWidgetItem(text, ui->switches);
|
||||
item->setData(Qt::UserRole, s.window.c_str());
|
||||
|
|
@ -429,7 +429,9 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
|
|||
obs_data_set_string(array_obj, "window_title",
|
||||
s.window.c_str());
|
||||
obs_data_set_bool(array_obj, "fullscreen",
|
||||
s.fullscreen);
|
||||
s.fullscreen);
|
||||
obs_data_set_bool(array_obj, "focus",
|
||||
s.focus);
|
||||
obs_data_array_push_back(array, array_obj);
|
||||
obs_source_release(source);
|
||||
obs_source_release(transition);
|
||||
|
|
@ -906,11 +908,14 @@ static void SaveSceneSwitcher(obs_data_t *save_data, bool saving, void *)
|
|||
obs_data_get_string(array_obj, "window_title");
|
||||
bool fullscreen =
|
||||
obs_data_get_bool(array_obj, "fullscreen");
|
||||
bool focus =
|
||||
obs_data_get_bool(array_obj, "focus");
|
||||
|
||||
switcher->windowSwitches.emplace_back(
|
||||
GetWeakSourceByName(scene), window,
|
||||
GetWeakTransitionByName(transition),
|
||||
fullscreen);
|
||||
fullscreen,
|
||||
focus);
|
||||
|
||||
obs_data_release(array_obj);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ public slots:
|
|||
* Windowtitle helper
|
||||
********************************************************************************/
|
||||
void GetWindowList(std::vector<std::string> &windows);
|
||||
void GetWindowList(QStringList &windows); // Overloaded
|
||||
void GetCurrentWindowTitle(std::string &title);
|
||||
bool isFullscreen();
|
||||
|
||||
|
|
|
|||
|
|
@ -42,13 +42,15 @@ struct WindowSceneSwitch {
|
|||
string window;
|
||||
OBSWeakSource transition;
|
||||
bool fullscreen;
|
||||
bool focus;
|
||||
|
||||
inline WindowSceneSwitch(OBSWeakSource scene_, const char *window_,
|
||||
OBSWeakSource transition_, bool fullscreen_)
|
||||
OBSWeakSource transition_, bool fullscreen_, bool focus_)
|
||||
: scene(scene_),
|
||||
window(window_),
|
||||
transition(transition_),
|
||||
fullscreen(fullscreen_)
|
||||
fullscreen(fullscreen_),
|
||||
focus(focus_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,14 +14,26 @@ static inline bool WeakSourceValid(obs_weak_source_t* ws)
|
|||
}
|
||||
|
||||
static inline QString MakeSwitchName(const QString &scene, const QString &value,
|
||||
const QString &transition, bool fullscreen)
|
||||
const QString &transition, bool fullscreen, bool focus)
|
||||
{
|
||||
if (!fullscreen)
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") +
|
||||
transition + QStringLiteral("]: ") + value;
|
||||
return QStringLiteral("[") + scene + QStringLiteral(", ") + transition +
|
||||
QStringLiteral("]: ") + value +
|
||||
QStringLiteral(" (only if window is fullscreen)");
|
||||
QString name = QStringLiteral("[") + scene + QStringLiteral(", ") +
|
||||
transition + QStringLiteral("]: ") + value;
|
||||
|
||||
if (fullscreen || focus)
|
||||
{
|
||||
name += QStringLiteral(" (only if");
|
||||
|
||||
if (fullscreen)
|
||||
name += QStringLiteral(" fullscreen");
|
||||
if (fullscreen && focus)
|
||||
name += QStringLiteral(" and");
|
||||
if (focus)
|
||||
name += QStringLiteral(" focused");
|
||||
|
||||
name += QStringLiteral(")");
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static inline QString MakeSwitchNameExecutable(const QString &scene,
|
||||
|
|
|
|||
|
|
@ -174,6 +174,17 @@ void GetWindowList(vector<string> &windows)
|
|||
}
|
||||
}
|
||||
|
||||
// Overloaded
|
||||
void GetWindowList(QStringList &windows)
|
||||
{
|
||||
windows.clear();
|
||||
|
||||
for (size_t i = 0; i < getTopLevelWindows().size(); ++i){
|
||||
if (GetWindowTitle(i) != "")
|
||||
windows << QString::fromStdString(GetWindowTitle(i));
|
||||
}
|
||||
}
|
||||
|
||||
void GetCurrentWindowTitle(string &title)
|
||||
{
|
||||
if (!ewmhIsSupported()) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,39 @@
|
|||
#include <obs-module.h>
|
||||
#include "headers/advanced-scene-switcher.hpp"
|
||||
|
||||
bool isRunning(std::string &title)
|
||||
{
|
||||
QStringList windows;
|
||||
|
||||
GetWindowList(windows);
|
||||
// True if switch is running (direct)
|
||||
bool equals = windows.contains(title.c_str());
|
||||
// True if switch is running (regex)
|
||||
bool matches = (windows.indexOf(QRegularExpression(title.c_str())) != -1);
|
||||
|
||||
return (equals || matches);
|
||||
}
|
||||
|
||||
bool isFocused(std::string &title)
|
||||
{
|
||||
string current;
|
||||
|
||||
GetCurrentWindowTitle(current);
|
||||
// True if switch equals current window
|
||||
bool equals = (title == current);
|
||||
// True if switch matches current window
|
||||
bool matches = QString::fromStdString(current).contains(QRegularExpression(title.c_str()));
|
||||
|
||||
return (equals || matches);
|
||||
}
|
||||
|
||||
void SceneSwitcher::on_add_clicked()
|
||||
{
|
||||
QString sceneName = ui->scenes->currentText();
|
||||
QString windowName = ui->windows->currentText();
|
||||
QString transitionName = ui->transitions->currentText();
|
||||
bool fullscreen = ui->fullscreenCheckBox->isChecked();
|
||||
bool focus = ui->focusCheckBox->isChecked();
|
||||
|
||||
if (windowName.isEmpty() || sceneName.isEmpty())
|
||||
return;
|
||||
|
|
@ -15,7 +42,7 @@ void SceneSwitcher::on_add_clicked()
|
|||
OBSWeakSource transition = GetWeakTransitionByQString(transitionName);
|
||||
QVariant v = QVariant::fromValue(windowName);
|
||||
|
||||
QString text = MakeSwitchName(sceneName, windowName, transitionName, fullscreen);
|
||||
QString text = MakeSwitchName(sceneName, windowName, transitionName, fullscreen, focus);
|
||||
|
||||
int idx = FindByData(windowName);
|
||||
|
||||
|
|
@ -23,7 +50,7 @@ void SceneSwitcher::on_add_clicked()
|
|||
{
|
||||
lock_guard<mutex> lock(switcher->m);
|
||||
switcher->windowSwitches.emplace_back(
|
||||
source, windowName.toUtf8().constData(), transition, fullscreen);
|
||||
source, windowName.toUtf8().constData(), transition, fullscreen, focus);
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(text, ui->switches);
|
||||
item->setData(Qt::UserRole, v);
|
||||
|
|
@ -44,6 +71,7 @@ void SceneSwitcher::on_add_clicked()
|
|||
s.scene = source;
|
||||
s.transition = transition;
|
||||
s.fullscreen = fullscreen;
|
||||
s.focus = focus;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -198,6 +226,7 @@ void SceneSwitcher::on_switches_currentRowChanged(int idx)
|
|||
ui->windows->setCurrentText(window);
|
||||
ui->transitions->setCurrentText(transitionName.c_str());
|
||||
ui->fullscreenCheckBox->setChecked(s.fullscreen);
|
||||
ui->focusCheckBox->setChecked(s.focus);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -229,18 +258,20 @@ void SceneSwitcher::on_ignoreWindows_currentRowChanged(int idx)
|
|||
void SwitcherData::checkWindowTitleSwitch(bool& match, OBSWeakSource& scene, OBSWeakSource& transition)
|
||||
{
|
||||
string title;
|
||||
bool ignored = false;
|
||||
|
||||
// Check if current window is ignored
|
||||
GetCurrentWindowTitle(title);
|
||||
for (auto& window : ignoreWindowsSwitches)
|
||||
{
|
||||
// True if ignored switch equals title
|
||||
// True if ignored switch equals current window
|
||||
bool equals = (title == window);
|
||||
// True if ignored switch matches title
|
||||
// True if ignored switch matches current window
|
||||
bool matches = QString::fromStdString(title).contains(QRegularExpression(window.c_str()));
|
||||
|
||||
if (equals || matches)
|
||||
{
|
||||
ignored = true;
|
||||
title = lastTitle;
|
||||
|
||||
break;
|
||||
|
|
@ -251,14 +282,14 @@ void SwitcherData::checkWindowTitleSwitch(bool& match, OBSWeakSource& scene, OBS
|
|||
// Check for match
|
||||
for (WindowSceneSwitch& s : windowSwitches)
|
||||
{
|
||||
// True if window switch equals title
|
||||
bool equals = (title == s.window);
|
||||
// True if window switch matches title
|
||||
bool matches = QString::fromStdString(title).contains(QRegularExpression(s.window.c_str()));
|
||||
// True if fullscreen is disabled OR window is fullscreen
|
||||
bool fullscreen = (!s.fullscreen || isFullscreen());
|
||||
// True if fullscreen is disabled OR current window is fullscreen
|
||||
bool fullscreen = (!s.fullscreen || isFullscreen(s.window));
|
||||
// True if focus is disabled OR switch is focused
|
||||
bool focus = (!s.focus || isFocused(s.window));
|
||||
// True if current window is ignored AND switch matches last window
|
||||
bool ignore = (ignored && QString::fromStdString(title).contains(QRegularExpression(s.window.c_str())));
|
||||
|
||||
if ((equals || matches) && fullscreen)
|
||||
if (isRunning(s.window) && (fullscreen && (focus || ignore)))
|
||||
{
|
||||
match = true;
|
||||
scene = s.scene;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user