Skip to content

Commit

Permalink
feat: Restore full functionality of Windows build
Browse files Browse the repository at this point in the history
Restore most of Windows-specific features and quirks.
  • Loading branch information
pktiuk authored Sep 21, 2021
2 parents 60f0ec9 + b28ea2c commit 7a9ec69
Show file tree
Hide file tree
Showing 29 changed files with 998 additions and 121 deletions.
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,26 @@ if(UNIX)

elseif(WIN32)
LIST(APPEND antimicrox_SOURCES
src/autoprofilewatcher.cpp
src/winextras.cpp
src/qtwinkeymapper.cpp
# src/winappprofiletimerdialog.cpp
# src/capturedwindowinfodialog.cpp
src/winappprofiletimerdialog.cpp
src/capturedwindowinfodialog.cpp
src/eventhandlers/winsendinputeventhandler.cpp
src/joykeyrepeathelper.cpp
)
LIST(APPEND antimicrox_HEADERS
src/autoprofilewatcher.h
src/winextras.h
src/qtwinkeymapper.h
# src/winappprofiletimerdialog.h
# src/capturedwindowinfodialog.h
src/winappprofiletimerdialog.h
src/capturedwindowinfodialog.h
src/eventhandlers/winsendinputeventhandler.h
src/joykeyrepeathelper.h
)
LIST(APPEND antimicrox_FORMS
src/winappprofiletimerdialog.ui
)
endif(UNIX)

###############################
Expand Down
65 changes: 55 additions & 10 deletions src/addeditautoprofiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
#include "common.h"
#include "inputdevice.h"

#ifdef WITH_X11
#if defined(Q_OS_UNIX)
#ifdef WITH_X11
#include "capturedwindowinfodialog.h"
#include "unixcapturewindowutility.h"
#include "x11extras.h"
#endif
#elif defined(Q_OS_WIN)
#include "capturedwindowinfodialog.h"
#include "unixcapturewindowutility.h"
#include "x11extras.h"
#include "winappprofiletimerdialog.h"
#include "winextras.h"
#endif

#include <QApplication>
Expand Down Expand Up @@ -103,7 +109,16 @@ AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMi
ui->applicationLineEdit->setText(info->getExe());
ui->winClassLineEdit->setText(info->getWindowClass());
ui->winNameLineEdit->setText(info->getWindowName());
#ifdef Q_OS_UNIX
ui->selectWindowPushButton->setVisible(false);
#elif defined(Q_OS_WIN)
ui->detectWinPropsSelectWindowPushButton->setVisible(false);

ui->winClassLineEdit->setVisible(false);
ui->winClassLabel->setVisible(false);
// ui->winNameLineEdit->setVisible(false);
// ui->winNameLabel->setVisible(false);
#endif
ui->asDefaultCheckBox->setEnabled(info->isCurrentDefault());

connect(ui->profileBrowsePushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::openProfileBrowseDialog);
Expand All @@ -115,10 +130,12 @@ AddEditAutoProfileDialog::AddEditAutoProfileDialog(AutoProfileInfo *info, AntiMi
connect(ui->applicationLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
connect(ui->winClassLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);
connect(ui->winNameLineEdit, &QLineEdit::textChanged, this, &AddEditAutoProfileDialog::checkForDefaultStatus);

#if defined(Q_OS_UNIX)
connect(ui->detectWinPropsSelectWindowPushButton, &QPushButton::clicked, this,
&AddEditAutoProfileDialog::showCaptureHelpWindow);

#elif defined(Q_OS_WIN)
connect(ui->selectWindowPushButton, &QPushButton::clicked, this, &AddEditAutoProfileDialog::openWinAppProfileDialog);
#endif
connect(this, &AddEditAutoProfileDialog::accepted, this, &AddEditAutoProfileDialog::saveAutoProfileInformation);

ui->asDefaultCheckBox->setChecked(info->isCurrentDefault());
Expand All @@ -145,8 +162,11 @@ void AddEditAutoProfileDialog::openProfileBrowseDialog()

void AddEditAutoProfileDialog::openApplicationBrowseDialog()
{
#ifdef Q_OS_WIN
QString filename = QFileDialog::getOpenFileName(this, tr("Select Program"), QDir::homePath(), tr("Programs (*.exe)"));
#else
QString filename = QFileDialog::getOpenFileName(this, tr("Select Program"), QDir::homePath(), QString());

#endif
if (!filename.isNull() && !filename.isEmpty())
{
QFileInfo exe(filename);
Expand Down Expand Up @@ -217,12 +237,13 @@ QString AddEditAutoProfileDialog::getOriginalWindowClass() const { return origin

QString AddEditAutoProfileDialog::getOriginalWindowName() const { return originalWindowName; }

#ifdef Q_OS_UNIX
/**
* @brief Display a simple message box and attempt to capture a window using the mouse
*/
void AddEditAutoProfileDialog::showCaptureHelpWindow()
{
#ifdef WITH_X11
#ifdef WITH_X11

if (QApplication::platformName() == QStringLiteral("xcb"))
{
Expand All @@ -249,7 +270,7 @@ void AddEditAutoProfileDialog::showCaptureHelpWindow()
thread->start();
}

#endif
#endif
}

/**
Expand All @@ -258,7 +279,7 @@ void AddEditAutoProfileDialog::showCaptureHelpWindow()
*/
void AddEditAutoProfileDialog::checkForGrabbedWindow(UnixCaptureWindowUtility *util)
{
#ifdef WITH_X11 if (QApplication::platformName() == QStringLiteral("xcb"))
#ifdef WITH_X11 if (QApplication::platformName() == QStringLiteral("xcb"))
{
long targetWindow = util->getTargetWindow();
bool escaped = !util->hasFailed();
Expand Down Expand Up @@ -305,8 +326,9 @@ void AddEditAutoProfileDialog::checkForGrabbedWindow(UnixCaptureWindowUtility *u
util->deleteLater();
}

#endif
#endif
}
#endif

void AddEditAutoProfileDialog::windowPropAssignment(CapturedWindowInfoDialog *dialog)
{
Expand Down Expand Up @@ -416,6 +438,13 @@ void AddEditAutoProfileDialog::accept()
validForm = false;
errorString = tr("Program path is invalid or not executable.");
}
#ifdef Q_OS_WIN
else if (!info.isAbsolute() && (info.fileName() != exeFileName || info.suffix() != "exe"))
{
validForm = false;
errorString = tr("File is not an .exe file.");
}
#endif
}

if (validForm && !propertyFound && !ui->asDefaultCheckBox->isChecked())
Expand Down Expand Up @@ -465,3 +494,19 @@ void AddEditAutoProfileDialog::checkDefaultCheckbox(const QString &text)
ui->asDefaultCheckBox->setDisabled(false);
}
}

#ifdef Q_OS_WIN
void AddEditAutoProfileDialog::openWinAppProfileDialog()
{
WinAppProfileTimerDialog *dialog = new WinAppProfileTimerDialog(this);
connect(dialog, SIGNAL(accepted()), this, SLOT(captureWindowsApplicationPath()));
dialog->show();
}

void AddEditAutoProfileDialog::captureWindowsApplicationPath()
{
CapturedWindowInfoDialog *dialog = new CapturedWindowInfoDialog(this);
connect(dialog, SIGNAL(accepted()), this, SLOT(windowPropAssignment()));
dialog->show();
}
#endif
9 changes: 7 additions & 2 deletions src/addeditautoprofiledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@ class AddEditAutoProfileDialog : public QDialog
void checkForReservedUniques(int index);
void checkForDefaultStatus();
void windowPropAssignment(CapturedWindowInfoDialog *dialog);
void showCaptureHelpWindow();
void checkForGrabbedWindow(UnixCaptureWindowUtility *util);
void on_setPartialCheckBox_stateChanged(int arg1);
void checkDefaultCheckbox(const QString &text);
#ifdef Q_OS_WIN
void openWinAppProfileDialog();
void captureWindowsApplicationPath();
#else
void showCaptureHelpWindow();
void checkForGrabbedWindow(UnixCaptureWindowUtility *util);
#endif

private:
Ui::AddEditAutoProfileDialog *ui;
Expand Down
2 changes: 2 additions & 0 deletions src/antimicrosettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <QDebug>

const bool AntiMicroSettings::defaultDisabledWinEnhanced = false;

AntiMicroSettings::AntiMicroSettings(const QString &fileName, Format format, QObject *parent)
: QSettings(fileName, format, parent)
{
Expand Down
2 changes: 2 additions & 0 deletions src/antimicrosettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class AntiMicroSettings : public QSettings
QMutex *getLock();
QSettings &getCmdSettings();

static const bool defaultDisabledWinEnhanced;

void applySettingsToLogger(CommandLineUtility &cmdutility, Logger *logger = nullptr);

protected:
Expand Down
30 changes: 30 additions & 0 deletions src/applaunchhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <QMapIterator>
#include <QThread>

#ifdef Q_OS_WIN
#include <winextras.h>
#endif

AppLaunchHelper::AppLaunchHelper(AntiMicroSettings *settings, bool graphical, QObject *parent)
: QObject(parent)
{
Expand All @@ -44,6 +48,9 @@ void AppLaunchHelper::initRunMethods()
changeMouseRefreshRate();
changeSpringModeScreen();
changeGamepadPollRate();
#ifdef Q_OS_WIN
checkPointerPrecision();
#endif
}
}

Expand Down Expand Up @@ -150,6 +157,29 @@ void AppLaunchHelper::changeSpringModeScreen()
JoyButton::setSpringModeScreen(springScreen, GlobalVariables::JoyButton::springModeScreen);
}

#ifdef Q_OS_WIN
void AppLaunchHelper::checkPointerPrecision()
{
WinExtras::grabCurrentPointerPrecision();
bool disableEnhandedPoint =
settings->value("Mouse/DisableWinEnhancedPointer", AntiMicroSettings::defaultDisabledWinEnhanced).toBool();
if (disableEnhandedPoint)
{
WinExtras::disablePointerPrecision();
}
}

void AppLaunchHelper::appQuitPointerPrecision()
{
bool disableEnhancedPoint =
settings->value("Mouse/DisableWinEnhancedPointer", AntiMicroSettings::defaultDisabledWinEnhanced).toBool();
if (disableEnhancedPoint && !WinExtras::isUsingEnhancedPointerPrecision())
{
WinExtras::enablePointerPrecision();
}
}
#endif

void AppLaunchHelper::revertMouseThread()
{
JoyButton::indirectStaticMouseThread(QThread::currentThread(), JoyButton::getStaticMouseEventTimer(),
Expand Down
6 changes: 6 additions & 0 deletions src/applaunchhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ class AppLaunchHelper : public QObject
void changeMouseRefreshRate();
void changeSpringModeScreen();
void changeGamepadPollRate();
#ifdef Q_OS_WIN
void checkPointerPrecision();
#endif

public slots:
#ifdef Q_OS_WIN
void appQuitPointerPrecision();
#endif
void initRunMethods();
void revertMouseThread();
void changeMouseThread(QThread *thread);
Expand Down
6 changes: 6 additions & 0 deletions src/autoprofileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ void AutoProfileInfo::setExe(QString exe)
{
this->exe = exe;
}
#ifdef Q_OS_WIN
else if (exe != this->exe && info.suffix() == "exe")
{
this->exe = exe;
}
#endif
} else
{
this->exe = exe;
Expand Down
50 changes: 40 additions & 10 deletions src/autoprofilewatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
#include <QSetIterator>
#include <QStringListIterator>

#if defined(WITH_X11)
#if defined(Q_OS_UNIX) && defined(WITH_X11)
#include "x11extras.h"

#elif defined(Q_OS_WIN)
#include "winextras.h"

#endif

AutoProfileWatcher *AutoProfileWatcher::_instance = nullptr;
Expand Down Expand Up @@ -83,11 +87,21 @@ void AutoProfileWatcher::runAppCheck()

// Check whether program path needs to be parsed. Removes processing time
// and need to run Linux specific code searching /proc.
if (!getAppProfileAssignments().isEmpty())
#ifdef Q_OS_LINUX
if (!appProfileAssignments.isEmpty())
{
appLocation = findAppLocation();
qDebug() << "appLocation is " << appLocation;
}
#else
// In Windows, get program location no matter what.
appLocation = findAppLocation();
if (!appLocation.isEmpty())
{
baseAppFileName = QFileInfo(appLocation).fileName();
}
#endif

qDebug() << "appLocation is " << appLocation;

// More portable check for whether antimicrox is the current application
// with focus.
Expand All @@ -97,7 +111,9 @@ void AutoProfileWatcher::runAppCheck()
QString nowWindow = QString();
QString nowWindowClass = QString();
QString nowWindowName = QString();

#ifdef Q_OS_WIN
nowWindowName = WinExtras::getCurrentWindowText();
#else
long currentWindow = X11Extras::getInstance()->getWindowInFocus();
qDebug() << "getWindowInFocus: " << currentWindow;

Expand All @@ -118,21 +134,32 @@ void AutoProfileWatcher::runAppCheck()
nowWindowName = X11Extras::getInstance()->getWindowTitle(static_cast<Window>(currentWindow));
qDebug() << "title of window now: " << nowWindowName;
}

qDebug() << "WINDOW CLASS: " << nowWindowClass;
qDebug() << "WINDOW NAME: " << nowWindowName;
qDebug() << "WINDOW IN FOCUS: " << nowWindow;
#endif
qDebug() << "WINDOW NAME: " << nowWindowName;

bool checkForTitleChange = getWindowNameProfileAssignments().size() > 0;

qDebug() << "window profile assignments size: " << getWindowNameProfileAssignments().size();

qDebug() << "checkForTitleChange: " << checkForTitleChange;

if (!focusedWidget && ((!nowWindow.isEmpty() && (nowWindow != currentApplication)) ||
(checkForTitleChange && (nowWindowName != currentAppWindowTitle))))
#ifdef Q_OS_WIN
if (!focusedWidget && ((!appLocation.isEmpty() && appLocation != currentApplication) ||
(checkForTitleChange && nowWindowName != currentAppWindowTitle)))

#else
if (!focusedWidget && ((!nowWindow.isEmpty() && nowWindow != currentApplication) ||
(checkForTitleChange && nowWindowName != currentAppWindowTitle)))

#endif
{
#ifdef Q_OS_WIN
currentApplication = appLocation;
#else
currentApplication = nowWindow;
#endif
currentAppWindowTitle = nowWindowName;

qInfo() << QObject::tr("Active window changed to: Title = \"%1\", "
Expand Down Expand Up @@ -539,8 +566,8 @@ void AutoProfileWatcher::clearProfileAssignments()
QString AutoProfileWatcher::findAppLocation()
{
QString exepath = QString();

#ifdef WITH_X11
#if defined(Q_OS_LINUX)
#ifdef WITH_X11
Window currentWindow = 0;
int pid = 0;

Expand All @@ -549,6 +576,9 @@ QString AutoProfileWatcher::findAppLocation()
pid = X11Extras::getInstance()->getApplicationPid(currentWindow);
if (pid > 0)
exepath = X11Extras::getInstance()->getApplicationLocation(pid);
#endif
#elif defined(Q_OS_WIN)
exepath = WinExtras::getForegroundWindowExePath();
#endif

return exepath;
Expand Down
Loading

0 comments on commit 7a9ec69

Please sign in to comment.