Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite code using QDesktopWidget Class #867

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/applaunchhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "joybuttontypes/joybutton.h"

#include <QDebug>
#include <QDesktopWidget>
#include <QMapIterator>
#include <QThread>

Expand Down
4 changes: 2 additions & 2 deletions src/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <QApplication>
#include <QCursor>
#include <QDebug>
#include <QDesktopWidget>
#include <QFileInfo>
#include <QMessageBox>
#include <QProcess>
Expand Down Expand Up @@ -316,7 +315,8 @@ void sendSpringEvent(PadderCommon::springModeInfo *fullSpring, PadderCommon::spr
fullSpring->screen = -1;
}

QRect deskRect = QGuiApplication::screens().at(fullSpring->screen)->geometry();
QRect deskRect = fullSpring->screen == -1 ? QGuiApplication::primaryScreen()->geometry()
: QGuiApplication::screens().at(fullSpring->screen)->geometry();

width = deskRect.width();
height = deskRect.height();
Expand Down
1 change: 0 additions & 1 deletion src/gui/mainsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QApplication>
#include <QComboBox>
#include <QDebug>
#include <QDesktopWidget>
#include <QDir>
#include <QFileDialog>
#include <QLabel>
Expand Down
3 changes: 0 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ int main(int argc, char *argv[])
PadderCommon::log_system_config(); // workaround for missing windows logs
#endif

PadderCommon::mouseHelperObj.initDeskWid();
QPointer<InputDaemon> joypad_worker = new InputDaemon(joysticks, &settings);
inputEventThread = new QThread();
inputEventThread->setObjectName("inputEventThread");
Expand All @@ -570,8 +569,6 @@ int main(int argc, char *argv[])
QObject::connect(&antimicrox, &QApplication::aboutToQuit, &mainAppHelper, &AppLaunchHelper::revertMouseThread);
QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::quit);
QObject::connect(&antimicrox, &QApplication::aboutToQuit, joypad_worker.data(), &InputDaemon::deleteLater);
QObject::connect(&antimicrox, &QApplication::aboutToQuit, &PadderCommon::mouseHelperObj, &MouseHelper::deleteDeskWid,
Qt::DirectConnection);

QObject::connect(localServer, &LocalAntiMicroServer::showHiddenWindow, mainWindow, &MainWindow::show);
QObject::connect(localServer, &LocalAntiMicroServer::clientdisconnect, mainWindow,
Expand Down
19 changes: 10 additions & 9 deletions src/mousedialog/springmoderegionpreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QPaintEvent>
#include <QPainter>
#include <QScreen>

SpringModeRegionPreview::SpringModeRegionPreview(int width, int height, QWidget *parent)
:
Expand All @@ -43,8 +43,9 @@ SpringModeRegionPreview::SpringModeRegionPreview(int width, int height, QWidget

if ((tempwidth >= 2) && (tempheight >= 2))
{
int cw = (qApp->desktop()->width() / 2) - (tempwidth / 2);
int ch = (qApp->desktop()->height() / 2) - (tempheight / 2);
// TODO create a simple class representing display fopr calculating cursor locations
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (tempwidth / 2);
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (tempheight / 2);

setGeometry(cw, ch, tempwidth, tempheight);
show();
Expand Down Expand Up @@ -108,8 +109,8 @@ void SpringModeRegionPreview::setSpringWidth(int width)

if ((tempwidth >= 2) && (height >= 2))
{
int cw = (qApp->desktop()->width() / 2) - (tempwidth / 2);
int ch = (qApp->desktop()->height() / 2) - (height / 2);
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (tempwidth / 2);
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (height / 2);

setGeometry(cw, ch, tempwidth, height);
if (!isVisible())
Expand All @@ -133,8 +134,8 @@ void SpringModeRegionPreview::setSpringHeight(int height)

if ((width >= 2) && (tempheight >= 2))
{
int cw = (qApp->desktop()->width() / 2) - (width / 2);
int ch = (qApp->desktop()->height() / 2) - (tempheight / 2);
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (width / 2);
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (tempheight / 2);

setGeometry(cw, ch, width, tempheight);
if (!isVisible())
Expand All @@ -153,8 +154,8 @@ void SpringModeRegionPreview::setSpringSize(int width, int height)
int tempwidth = adjustSpringSizeWidth(width);
int tempheight = adjustSpringSizeHeight(height);

int cw = (qApp->desktop()->width() / 2) - (tempwidth / 2);
int ch = (qApp->desktop()->height() / 2) - (height / 2);
int cw = (QGuiApplication::primaryScreen()->virtualGeometry().width() / 2) - (tempwidth / 2);
int ch = (QGuiApplication::primaryScreen()->virtualGeometry().height() / 2) - (height / 2);

resize(tempwidth, tempheight);
move(cw, ch);
Expand Down
18 changes: 0 additions & 18 deletions src/mousehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "mousehelper.h"

#include <QDebug>
#include <QDesktopWidget>

MouseHelper::MouseHelper(QObject *parent)
: QObject(parent)
Expand All @@ -35,20 +34,3 @@ MouseHelper::MouseHelper(QObject *parent)
}

void MouseHelper::resetSpringMouseMoving() { springMouseMoving = false; }

void MouseHelper::initDeskWid()
{
if (deskWid == nullptr)
deskWid = new QDesktopWidget;
}

void MouseHelper::deleteDeskWid()
{
if (deskWid != nullptr)
{
delete deskWid;
deskWid = nullptr;
}
}

QDesktopWidget *MouseHelper::getDesktopWidget() const { return deskWid; }
10 changes: 0 additions & 10 deletions src/mousehelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,19 @@
#include <QObject>
#include <QTimer>

class QDesktopWidget;

class MouseHelper : public QObject
{
Q_OBJECT

public:
explicit MouseHelper(QObject *parent = nullptr);
QDesktopWidget *getDesktopWidget() const;
bool springMouseMoving;
int previousCursorLocation[2];
int pivotPoint[2];
QTimer mouseTimer;

public slots:
void deleteDeskWid();
void initDeskWid();

private slots:
void resetSpringMouseMoving();

private:
QDesktopWidget *deskWid;
};

#endif // MOUSEHELPER_H
2 changes: 1 addition & 1 deletion src/springmousemoveinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct _springModeInfo
// Should the cursor not move around the center
// of the screen.
bool relative;
int screen;
int screen; //-1 for default screen
double springDeadX;
double springDeadY;

Expand Down