mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-03-21 17:34:57 -05:00
Change isInFocus() check to be OS-agnostic
isInFocus() can utilize the platform-dependent GetCurrentWindowTitle() instead of re-implementing the same functionality. Tested on Linux and macOS without issues
This commit is contained in:
parent
ac051a42a8
commit
a4de8c0c59
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user