diff --git a/src/osx/advanced-scene-switcher-osx.mm b/src/osx/advanced-scene-switcher-osx.mm index 729c359a..372e5c63 100644 --- a/src/osx/advanced-scene-switcher-osx.mm +++ b/src/osx/advanced-scene-switcher-osx.mm @@ -126,21 +126,15 @@ void GetProcessList(QStringList& list) } } -bool isInFocus(QString const& appQName) +bool isInFocus(const QString &exeToCheck) { - QByteArray ba = appQName.toLocal8Bit(); - const char * appName = ba.data(); - @autoreleasepool { - NSWorkspace *ws = [NSWorkspace sharedWorkspace]; - NSRunningApplication *app = [ws frontmostApplication]; - if (app) { - NSString *name = app.localizedName; - if (!name) - return false; - - const char *str = name.UTF8String; - return (str && *str && strcmp(appName,str) == 0 )? true : false; - } - } - return false; + string curWindow; + GetCurrentWindowTitle(curWindow); + + // True if executable switch equals current window + bool equals = (exeToCheck.toStdString() == curWindow); + // True if executable switch matches current window + bool matches = QString::fromStdString(curWindow).contains(QRegularExpression(exeToCheck)); + + return (equals || matches); } diff --git a/src/win/advanced-scene-switcher-win.cpp b/src/win/advanced-scene-switcher-win.cpp index d20bb9e5..dc42d67f 100644 --- a/src/win/advanced-scene-switcher-win.cpp +++ b/src/win/advanced-scene-switcher-win.cpp @@ -131,21 +131,17 @@ void GetProcessList(QStringList &processes) { CloseHandle(procSnapshot); } -bool isInFocus(const QString &exeToCheck) { - // only checks if the current foreground window is from the same executable, - // may return true for incorrent not meant windows from a program - HWND foregroundWindow = GetForegroundWindow(); - DWORD processId = 0; - GetWindowThreadProcessId(foregroundWindow, &processId); +bool isInFocus(const QString &exeToCheck) +{ + string curWindow; + GetCurrentWindowTitle(curWindow); - HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId); - if (process == NULL) return false; + // True if executable switch equals current window + bool equals = (exeToCheck.toStdString() == curWindow); + // True if executable switch matches current window + bool matches = QString::fromStdString(curWindow).contains(QRegularExpression(exeToCheck)); - WCHAR executablePath[600]; - GetModuleFileNameEx(process, 0, executablePath, 600); - CloseHandle(process); - - return exeToCheck == QString::fromWCharArray(executablePath).split(QRegExp("(/|\\\\)")).back(); + return (equals || matches); } int getLastInputTime()