mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-05-09 04:32:13 -05:00
Cleanup / style changes
This commit is contained in:
parent
f01a80c013
commit
8d21e89018
|
|
@ -322,8 +322,7 @@ void SwitcherData::SetPreconditions()
|
|||
{
|
||||
// Window title
|
||||
lastTitle = currentTitle;
|
||||
std::string title;
|
||||
GetCurrentWindowTitle(title);
|
||||
auto title = GetCurrentWindowTitle();
|
||||
for (auto &window : ignoreWindowsSwitches) {
|
||||
bool equals = (title == window);
|
||||
bool matches = false;
|
||||
|
|
@ -343,7 +342,7 @@ void SwitcherData::SetPreconditions()
|
|||
currentTitle = title;
|
||||
|
||||
// Process name
|
||||
GetForegroundProcessName(currentForegroundProcess);
|
||||
currentForegroundProcess = GetForegroundProcessName();
|
||||
|
||||
// Macro
|
||||
InvalidateMacroTempVarValues();
|
||||
|
|
|
|||
|
|
@ -92,12 +92,11 @@ bool SwitcherData::checkExeSwitch(OBSWeakSource &scene,
|
|||
}
|
||||
|
||||
std::string title = switcher->currentTitle;
|
||||
QStringList runningProcesses;
|
||||
bool ignored = false;
|
||||
bool match = false;
|
||||
|
||||
// Check for match
|
||||
GetProcessList(runningProcesses);
|
||||
const auto runningProcesses = GetProcessList();
|
||||
for (ExecutableSwitch &s : executableSwitches) {
|
||||
if (!s.initialized()) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -230,8 +230,7 @@ bool SwitcherData::checkWindowTitleSwitch(OBSWeakSource &scene,
|
|||
|
||||
std::string currentWindowTitle = switcher->currentTitle;
|
||||
bool match = false;
|
||||
std::vector<std::string> windowList;
|
||||
GetWindowList(windowList);
|
||||
const auto windowList = GetWindowList();
|
||||
|
||||
for (WindowSwitch &s : windowSwitches) {
|
||||
if (!s.initialized()) {
|
||||
|
|
|
|||
|
|
@ -236,9 +236,9 @@ std::string getWindowName(Window window)
|
|||
return windowTitle;
|
||||
}
|
||||
|
||||
void GetWindowList(std::vector<std::string> &windows)
|
||||
std::vector<std::string> GetWindowList()
|
||||
{
|
||||
windows.resize(0);
|
||||
std::vector<std::string> windows;
|
||||
for (auto window : getTopLevelWindows()) {
|
||||
auto name = getWindowName(window);
|
||||
if (name.empty()) {
|
||||
|
|
@ -246,18 +246,7 @@ void GetWindowList(std::vector<std::string> &windows)
|
|||
}
|
||||
windows.emplace_back(name);
|
||||
}
|
||||
}
|
||||
|
||||
void GetWindowList(QStringList &windows)
|
||||
{
|
||||
windows.clear();
|
||||
for (auto window : getTopLevelWindows()) {
|
||||
auto name = getWindowName(window);
|
||||
if (name.empty()) {
|
||||
continue;
|
||||
}
|
||||
windows << QString::fromStdString(name);
|
||||
}
|
||||
return windows;
|
||||
}
|
||||
|
||||
int getActiveWindow(Window *&window)
|
||||
|
|
@ -281,29 +270,24 @@ int getActiveWindow(Window *&window)
|
|||
&bytes, (uint8_t **)&window);
|
||||
}
|
||||
|
||||
void GetCurrentWindowTitle(std::string &title)
|
||||
std::string GetCurrentWindowTitle()
|
||||
{
|
||||
if (KWin) {
|
||||
title = FocusNotifier::getActiveWindowTitle();
|
||||
return;
|
||||
return FocusNotifier::getActiveWindowTitle();
|
||||
}
|
||||
|
||||
Window *data = 0;
|
||||
if (getActiveWindow(data) != Success || !data) {
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
if (!data[0]) {
|
||||
XFree(data);
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
auto name = getWindowName(data[0]);
|
||||
XFree(data);
|
||||
|
||||
if (name.empty()) {
|
||||
return;
|
||||
}
|
||||
title = name;
|
||||
return name;
|
||||
}
|
||||
|
||||
bool windowStatesAreSet(const std::string &windowTitle,
|
||||
|
|
@ -412,16 +396,17 @@ static void getProcessListProcps2(QStringList &processes)
|
|||
#endif
|
||||
}
|
||||
|
||||
void GetProcessList(QStringList &processes)
|
||||
QStringList GetProcessList()
|
||||
{
|
||||
processes.clear();
|
||||
QStringList processes;
|
||||
if (libprocpsSupported) {
|
||||
getProcessListProcps(processes);
|
||||
return;
|
||||
return processes;
|
||||
}
|
||||
if (libprocps2Supported) {
|
||||
getProcessListProcps2(processes);
|
||||
}
|
||||
return processes;
|
||||
}
|
||||
|
||||
long getForegroundProcessPid()
|
||||
|
|
@ -472,18 +457,10 @@ std::string getProcNameFromPid(long pid)
|
|||
return name;
|
||||
}
|
||||
|
||||
void GetForegroundProcessName(QString &proc)
|
||||
std::string GetForegroundProcessName()
|
||||
{
|
||||
std::string temp;
|
||||
GetForegroundProcessName(temp);
|
||||
proc = QString::fromStdString(temp);
|
||||
}
|
||||
|
||||
void GetForegroundProcessName(std::string &proc)
|
||||
{
|
||||
proc.resize(0);
|
||||
auto pid = getForegroundProcessPid();
|
||||
proc = getProcNameFromPid(pid);
|
||||
return getProcNameFromPid(pid);
|
||||
}
|
||||
|
||||
static std::string getProcessPathFromPid(long pid)
|
||||
|
|
@ -556,8 +533,7 @@ QStringList GetProcessPathsFromName(const QString &name)
|
|||
|
||||
bool IsInFocus(const QString &executable)
|
||||
{
|
||||
std::string current;
|
||||
GetForegroundProcessName(current);
|
||||
const auto current = GetForegroundProcessName();
|
||||
|
||||
// True if executable switch equals current window
|
||||
bool equals = (executable.toStdString() == current);
|
||||
|
|
|
|||
|
|
@ -14,10 +14,9 @@
|
|||
|
||||
namespace advss {
|
||||
|
||||
void GetWindowList(std::vector<std::string> &windows)
|
||||
std::vector<std::string> GetWindowList()
|
||||
{
|
||||
windows.resize(0);
|
||||
|
||||
std::vector<std::string> windows;
|
||||
@autoreleasepool {
|
||||
CFArrayRef cfApps = CGWindowListCopyWindowInfo(
|
||||
kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
|
||||
|
|
@ -49,21 +48,12 @@ void GetWindowList(std::vector<std::string> &windows)
|
|||
apps = nil;
|
||||
CFRelease(cfApps);
|
||||
}
|
||||
return windows;
|
||||
}
|
||||
|
||||
void GetWindowList(QStringList &windows)
|
||||
std::string GetCurrentWindowTitle()
|
||||
{
|
||||
windows.clear();
|
||||
std::vector<std::string> temp;
|
||||
GetWindowList(temp);
|
||||
for (auto &w : temp) {
|
||||
windows << QString::fromStdString(w);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCurrentWindowTitle(std::string &title)
|
||||
{
|
||||
title.resize(0);
|
||||
std::string title;
|
||||
@autoreleasepool {
|
||||
CFArrayRef cfApps = CGWindowListCopyWindowInfo(
|
||||
kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
|
||||
|
|
@ -107,6 +97,7 @@ void GetCurrentWindowTitle(std::string &title)
|
|||
apps = nil;
|
||||
CFRelease(cfApps);
|
||||
}
|
||||
return title;
|
||||
}
|
||||
|
||||
bool isWindowOriginOnScreen(NSDictionary *app, NSScreen *screen,
|
||||
|
|
@ -273,9 +264,9 @@ int SecondsSinceLastInput()
|
|||
return (int)time;
|
||||
}
|
||||
|
||||
void GetProcessList(QStringList &list)
|
||||
QStringList GetProcessList()
|
||||
{
|
||||
list.clear();
|
||||
QStringList list;
|
||||
@autoreleasepool {
|
||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||
NSArray *array = [ws runningApplications];
|
||||
|
|
@ -291,11 +282,11 @@ void GetProcessList(QStringList &list)
|
|||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void GetForegroundProcessName(std::string &proc)
|
||||
std::string GetForegroundProcessName()
|
||||
{
|
||||
proc.resize(0);
|
||||
@autoreleasepool {
|
||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||
NSArray *array = [ws runningApplications];
|
||||
|
|
@ -308,17 +299,13 @@ void GetForegroundProcessName(std::string &proc)
|
|||
break;
|
||||
}
|
||||
const char *str = name.UTF8String;
|
||||
proc = std::string(str);
|
||||
if (str) {
|
||||
return str;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GetForegroundProcessName(QString &proc)
|
||||
{
|
||||
std::string temp;
|
||||
GetForegroundProcessName(temp);
|
||||
proc = QString::fromStdString(temp);
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string GetForegroundProcessPath()
|
||||
|
|
@ -378,8 +365,7 @@ QStringList GetProcessPathsFromName(const QString &name)
|
|||
|
||||
bool IsInFocus(const QString &executable)
|
||||
{
|
||||
std::string current;
|
||||
GetForegroundProcessName(current);
|
||||
const auto current = GetForegroundProcessName();
|
||||
|
||||
// True if executable switch equals current window
|
||||
bool equals = (executable.toStdString() == current);
|
||||
|
|
|
|||
|
|
@ -11,15 +11,14 @@ namespace advss {
|
|||
|
||||
enum class HotkeyType;
|
||||
|
||||
EXPORT void GetWindowList(std::vector<std::string> &windows);
|
||||
EXPORT void GetWindowList(QStringList &windows);
|
||||
EXPORT void GetCurrentWindowTitle(std::string &title);
|
||||
EXPORT std::vector<std::string> GetWindowList();
|
||||
EXPORT std::string GetCurrentWindowTitle();
|
||||
EXPORT bool IsFullscreen(const std::string &title);
|
||||
EXPORT bool IsMaximized(const std::string &title);
|
||||
EXPORT std::optional<std::string> GetTextInWindow(const std::string &window);
|
||||
EXPORT int SecondsSinceLastInput();
|
||||
EXPORT void GetProcessList(QStringList &processes);
|
||||
EXPORT void GetForegroundProcessName(std::string &name);
|
||||
EXPORT QStringList GetProcessList();
|
||||
EXPORT std::string GetForegroundProcessName();
|
||||
EXPORT std::string GetForegroundProcessPath();
|
||||
EXPORT QStringList GetProcessPathsFromName(const QString &name);
|
||||
EXPORT bool IsInFocus(const QString &executable);
|
||||
|
|
|
|||
|
|
@ -55,9 +55,7 @@ static void WriteFirstRun(bool value)
|
|||
|
||||
static QString DetectFocusedWindow()
|
||||
{
|
||||
std::string title;
|
||||
GetCurrentWindowTitle(title);
|
||||
return QString::fromStdString(title);
|
||||
return QString::fromStdString(GetCurrentWindowTitle());
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
|
|
|||
|
|
@ -173,10 +173,9 @@ void PopulateTransitionSelection(QComboBox *sel, bool addCurrent, bool addAny,
|
|||
void PopulateWindowSelection(QComboBox *sel, bool addSelect)
|
||||
{
|
||||
|
||||
std::vector<std::string> windows;
|
||||
GetWindowList(windows);
|
||||
const auto windows = GetWindowList();
|
||||
|
||||
for (std::string &window : windows) {
|
||||
for (const std::string &window : windows) {
|
||||
sel->addItem(window.c_str());
|
||||
}
|
||||
|
||||
|
|
@ -257,8 +256,7 @@ void PopulateMediaSelection(QComboBox *sel, bool addSelect)
|
|||
|
||||
void PopulateProcessSelection(QComboBox *sel, bool addSelect)
|
||||
{
|
||||
QStringList processes;
|
||||
GetProcessList(processes);
|
||||
auto processes = GetProcessList();
|
||||
processes.sort();
|
||||
for (QString &process : processes) {
|
||||
sel->addItem(process);
|
||||
|
|
|
|||
|
|
@ -133,9 +133,9 @@ const std::vector<std::string> getOBSWindows()
|
|||
return lastDoneHelper->windows;
|
||||
}
|
||||
|
||||
void GetWindowList(std::vector<std::string> &windows)
|
||||
std::vector<std::string> GetWindowList()
|
||||
{
|
||||
windows.resize(0);
|
||||
std::vector<std::string> windows;
|
||||
EnumWindowsWithMetro(GetTitleCB, reinterpret_cast<LPARAM>(&windows));
|
||||
|
||||
// Also add OBS windows
|
||||
|
|
@ -147,20 +147,10 @@ void GetWindowList(std::vector<std::string> &windows)
|
|||
|
||||
// Add entry for OBS Studio itself - see GetCurrentWindowTitle()
|
||||
windows.emplace_back("OBS");
|
||||
return windows;
|
||||
}
|
||||
|
||||
void GetWindowList(QStringList &windows)
|
||||
{
|
||||
windows.clear();
|
||||
|
||||
std::vector<std::string> w;
|
||||
GetWindowList(w);
|
||||
for (auto window : w) {
|
||||
windows << QString::fromStdString(window);
|
||||
}
|
||||
}
|
||||
|
||||
void GetCurrentWindowTitle(std::string &title)
|
||||
std::string GetCurrentWindowTitle()
|
||||
{
|
||||
HWND window = GetForegroundWindow();
|
||||
DWORD pid;
|
||||
|
|
@ -178,15 +168,15 @@ void GetCurrentWindowTitle(std::string &title)
|
|||
//
|
||||
// So instead rely on Qt to get the title of the active window.
|
||||
if (GetCurrentProcessId() == pid) {
|
||||
auto window = QApplication::activeWindow();
|
||||
if (window) {
|
||||
title = window->windowTitle().toStdString();
|
||||
} else {
|
||||
title = "OBS";
|
||||
auto obsWindow = QApplication::activeWindow();
|
||||
if (obsWindow) {
|
||||
return obsWindow->windowTitle().toStdString();
|
||||
}
|
||||
return;
|
||||
return "OBS";
|
||||
}
|
||||
std::string title;
|
||||
GetWindowTitle(window, title);
|
||||
return title;
|
||||
}
|
||||
|
||||
static HWND getHWNDfromTitle(const std::string &title)
|
||||
|
|
@ -350,22 +340,22 @@ bool IsFullscreen(const std::string &title)
|
|||
return false;
|
||||
}
|
||||
|
||||
void GetProcessList(QStringList &processes)
|
||||
QStringList GetProcessList()
|
||||
{
|
||||
|
||||
QStringList processes;
|
||||
HANDLE procSnapshot;
|
||||
PROCESSENTRY32 procEntry;
|
||||
|
||||
procSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
if (procSnapshot == INVALID_HANDLE_VALUE) {
|
||||
return;
|
||||
return processes;
|
||||
}
|
||||
|
||||
procEntry.dwSize = sizeof(PROCESSENTRY32);
|
||||
|
||||
if (!Process32First(procSnapshot, &procEntry)) {
|
||||
CloseHandle(procSnapshot);
|
||||
return;
|
||||
return processes;
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
@ -383,9 +373,10 @@ void GetProcessList(QStringList &processes)
|
|||
} while (Process32Next(procSnapshot, &procEntry));
|
||||
|
||||
CloseHandle(procSnapshot);
|
||||
return processes;
|
||||
}
|
||||
|
||||
static void GetForegroundProcessName(QString &proc)
|
||||
static QString getForegroundProcessNameStr()
|
||||
{
|
||||
// only checks if the current foreground window is from the same executable,
|
||||
// may return true for any window from a program
|
||||
|
|
@ -396,23 +387,21 @@ static void GetForegroundProcessName(QString &proc)
|
|||
HANDLE process = OpenProcess(
|
||||
PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
|
||||
if (process == NULL) {
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
WCHAR executablePath[600];
|
||||
GetModuleFileNameEx(process, 0, executablePath, 600);
|
||||
CloseHandle(process);
|
||||
|
||||
proc = QString::fromWCharArray(executablePath)
|
||||
.split(QRegularExpression("(/|\\\\)"))
|
||||
.back();
|
||||
return QString::fromWCharArray(executablePath)
|
||||
.split(QRegularExpression("(/|\\\\)"))
|
||||
.back();
|
||||
}
|
||||
|
||||
void GetForegroundProcessName(std::string &proc)
|
||||
std::string GetForegroundProcessName()
|
||||
{
|
||||
QString temp;
|
||||
GetForegroundProcessName(temp);
|
||||
proc = temp.toStdString();
|
||||
return getForegroundProcessNameStr().toStdString();
|
||||
}
|
||||
|
||||
std::string GetForegroundProcessPath()
|
||||
|
|
@ -481,8 +470,7 @@ bool IsInFocus(const QString &executable)
|
|||
{
|
||||
// only checks if the current foreground window is from the same executable,
|
||||
// may return true for any window from a program
|
||||
QString foregroundProc;
|
||||
GetForegroundProcessName(foregroundProc);
|
||||
const auto foregroundProc = getForegroundProcessNameStr();
|
||||
|
||||
// True if executable switch equals current window
|
||||
bool equals = (executable == foregroundProc);
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ void CloseWindow(const std::string &) {}
|
|||
|
||||
std::optional<std::string> MacroActionWindow::GetMatchingWindow() const
|
||||
{
|
||||
std::vector<std::string> windowList;
|
||||
GetWindowList(windowList);
|
||||
const auto windowList = GetWindowList();
|
||||
|
||||
if (!_regex.Enabled()) {
|
||||
if (std::find(windowList.begin(), windowList.end(),
|
||||
|
|
|
|||
|
|
@ -16,8 +16,7 @@ bool MacroConditionProcess::_registered = MacroConditionFactory::Register(
|
|||
|
||||
bool MacroConditionProcess::CheckCondition()
|
||||
{
|
||||
std::string foregroundProcessName;
|
||||
GetForegroundProcessName(foregroundProcessName);
|
||||
const auto foregroundProcessName = GetForegroundProcessName();
|
||||
SetVariableValue(foregroundProcessName);
|
||||
|
||||
const QString proc = QString::fromStdString(_process);
|
||||
|
|
@ -58,8 +57,7 @@ bool MacroConditionProcess::CheckCondition()
|
|||
return true;
|
||||
}
|
||||
|
||||
QStringList runningProcesses;
|
||||
GetProcessList(runningProcesses);
|
||||
const auto runningProcesses = GetProcessList();
|
||||
|
||||
for (const auto &process : runningProcesses) {
|
||||
bool nameMatches = _regex.Enabled()
|
||||
|
|
@ -275,9 +273,8 @@ void MacroConditionProcessEdit::PathRegexChanged(const RegexConfig &conf)
|
|||
|
||||
void MacroConditionProcessEdit::UpdateFocusProcess()
|
||||
{
|
||||
std::string name;
|
||||
GetForegroundProcessName(name);
|
||||
_focusProcess->setText(QString::fromStdString(name));
|
||||
_focusProcess->setText(
|
||||
QString::fromStdString(GetForegroundProcessName()));
|
||||
}
|
||||
|
||||
void MacroConditionProcessEdit::SetWidgetVisibility()
|
||||
|
|
|
|||
|
|
@ -135,8 +135,7 @@ static bool foregroundWindowChanged()
|
|||
|
||||
bool MacroConditionWindow::CheckCondition()
|
||||
{
|
||||
std::vector<std::string> windowList;
|
||||
GetWindowList(windowList);
|
||||
const auto windowList = GetWindowList();
|
||||
bool match = false;
|
||||
if (_windowRegex.Enabled()) {
|
||||
match = WindowRegexMatches(windowList);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user