Skip to content

Commit

Permalink
Add support for DPI stages
Browse files Browse the repository at this point in the history
  • Loading branch information
z3ntu committed Dec 16, 2023
1 parent 21a0308 commit 7d4b9da
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions include/libopenrazer/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ class Device : public QObject
*/
virtual ::openrazer::RazerDPI getDPI() = 0;

/*!
* Sets the DPI stages of the mouse to the specified \a dpiStages and sets stage nr. \a activeStage active.
* A maximum of 5 stages are possible.
* The active stage is 1-indexed.
* The DPI value of each must not exceed the maximum DPI of the device.
*
* \sa getDPIStages(), maxDPI()
*/
virtual void setDPIStages(uchar activeStage, QVector<::openrazer::RazerDPI> dpiStages) = 0;

/*!
* Returns a pair of the active DPI stage and the configured DPI stages of the mouse.
* A maximum of 5 stages are possible.
* The active stage is 1-indexed.
* Ex: 3, [(500, 500), (1500, 1500), (1800, 1800)]
*
* \sa setDPIStages(), maxDPI()
*/
virtual QPair<uchar, QVector<::openrazer::RazerDPI>> getDPIStages() = 0;

/*!
* Returns the maximum DPI possible for the device.
*
Expand Down Expand Up @@ -180,6 +200,8 @@ class Device : public ::libopenrazer::Device
QVector<ushort> getSupportedPollRates() override;
void setDPI(::openrazer::RazerDPI dpi) override;
::openrazer::RazerDPI getDPI() override;
void setDPIStages(uchar activeStage, QVector<::openrazer::RazerDPI> dpiStages) override;
QPair<uchar, QVector<::openrazer::RazerDPI>> getDPIStages() override;
ushort maxDPI() override;
QVector<ushort> getAllowedDPI() override;
void displayCustomFrame() override;
Expand Down Expand Up @@ -222,6 +244,8 @@ class Device : public ::libopenrazer::Device
QVector<ushort> getSupportedPollRates() override;
void setDPI(::openrazer::RazerDPI dpi) override;
::openrazer::RazerDPI getDPI() override;
void setDPIStages(uchar activeStage, QVector<::openrazer::RazerDPI> dpiStages) override;
QPair<uchar, QVector<::openrazer::RazerDPI>> getDPIStages() override;
ushort maxDPI() override;
QVector<ushort> getAllowedDPI() override;
void displayCustomFrame() override;
Expand Down
2 changes: 2 additions & 0 deletions include/libopenrazer/openrazer.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ inline void registerMetaTypes()
qDBusRegisterMetaType<RazerDPI>();
qRegisterMetaType<QVector<RazerDPI>>("QVector<RazerDPI>");
qDBusRegisterMetaType<QVector<RazerDPI>>();
qRegisterMetaType<QPair<uchar, QVector<::openrazer::RazerDPI>>>("QPair<uchar, QVector<RazerDPI>>");
qDBusRegisterMetaType<QPair<uchar, QVector<::openrazer::RazerDPI>>>();

qRegisterMetaType<ReactiveSpeed>("ReactiveSpeed");
qDBusRegisterMetaType<ReactiveSpeed>();
Expand Down
7 changes: 7 additions & 0 deletions src/demo/libopenrazerdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ int main(int argc, char *argv[])
} else {
device->setDPI({ 500, 500 });
}
if (device->hasFeature("dpi_stages")) {
QPair<uchar, QVector<openrazer::RazerDPI>> dpiStages = device->getDPIStages();
qDebug() << "DPI stages:" << dpiStages;
device->setDPIStages(2, { { 400, 500 }, { 600, 700 }, { 800, 900 } });
// restore DPI stages
device->setDPIStages(dpiStages.first, dpiStages.second);
}
qDebug() << "Maximum DPI:" << device->maxDPI();
// restore DPI
device->setDPI(dpi);
Expand Down
14 changes: 14 additions & 0 deletions src/openrazer/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void DevicePrivate::setupCapabilities()
supportedFeatures.append("dpi");
if (hasCapabilityInternal("razer.device.dpi", "availableDPI"))
supportedFeatures.append("restricted_dpi");
if (hasCapabilityInternal("razer.device.dpi", "setDPIStages"))
supportedFeatures.append("dpi_stages");
if (hasCapabilityInternal("razer.device.misc", "setPollRate"))
supportedFeatures.append("poll_rate");
if (hasCapabilityInternal("razer.device.lighting.chroma", "setCustom"))
Expand Down Expand Up @@ -249,6 +251,18 @@ ::openrazer::RazerDPI Device::getDPI()
}
}

void Device::setDPIStages(uchar activeStage, QVector<::openrazer::RazerDPI> dpiStages)
{
QDBusReply<void> reply = d->deviceDpiIface()->call("setDPIStages", QVariant::fromValue(activeStage), QVariant::fromValue(dpiStages));
handleDBusReply(reply, Q_FUNC_INFO);
}

QPair<uchar, QVector<::openrazer::RazerDPI>> Device::getDPIStages()
{
QDBusReply<QPair<uchar, QVector<::openrazer::RazerDPI>>> reply = d->deviceDpiIface()->call("getDPIStages");
return handleDBusReply(reply, Q_FUNC_INFO);
}

ushort Device::maxDPI()
{
QDBusReply<int> reply = d->deviceDpiIface()->call("maxDPI");
Expand Down
11 changes: 11 additions & 0 deletions src/razer_test/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ ::openrazer::RazerDPI Device::getDPI()
return handleDBusReply(reply, Q_FUNC_INFO);
}

void Device::setDPIStages(uchar activeStage, QVector<::openrazer::RazerDPI> dpiStages)
{
// TODO Needs implementation
}

QPair<uchar, QVector<::openrazer::RazerDPI>> Device::getDPIStages()
{
// TODO Needs implementation
return { 0, {} };
}

ushort Device::maxDPI()
{
QDBusReply<ushort> reply = d->deviceIface()->call("getMaxDPI");
Expand Down

0 comments on commit 7d4b9da

Please sign in to comment.