author | František Kučera <franta-hg@frantovo.cz> |
Tue, 09 Jun 2020 16:12:00 +0200 | |
branch | v_0 |
changeset 29 | 361687fe303a |
parent 26 | fff8e9a86e85 |
child 31 | 3cbac1956f05 |
permissions | -rw-r--r-- |
12 | 1 |
/** |
2 |
* cadMousePro |
|
3 |
* Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
26
fff8e9a86e85
fix license version: GNU GPLv3
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
12 | 8 |
* |
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
19 |
#include <iostream> |
|
20 |
#include <QObject> |
|
21 |
#include <QDBusContext> |
|
13
52d92c1b340e
generate C++ classes from D-Bus XML using cmake instead of a custom script
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
22 |
#include <QDBusConnection> |
12 | 23 |
|
24 |
#include "HID.h" |
|
25 |
#include "CadMouseConfig.h" |
|
26 |
#include "Common.h" |
|
27 |
||
28 |
class Daemon : public QObject, public QDBusContext { |
|
29 |
Q_OBJECT; |
|
30 |
||
31 |
private: |
|
32 |
||
33 |
HIDDevice getMouse() { |
|
34 |
return HIDDevice(VENDOR_ID, PRODUCT_ID, nullptr); |
|
35 |
} |
|
36 |
||
37 |
void logException(const HIDException& e) { |
|
38 |
std::wcout << L"HIDException: " << e.getMessage() << std::endl; |
|
39 |
} |
|
40 |
public: |
|
41 |
||
42 |
static unsigned short const VENDOR_ID = 0x256f; |
|
43 |
static unsigned short const PRODUCT_ID = 0xc652; |
|
44 |
||
45 |
Daemon(QObject* parent = nullptr) : QObject(parent) { |
|
46 |
} |
|
47 |
||
48 |
Q_PROPERTY(bool devicePresent READ devicePresent) |
|
49 |
bool devicePresent() { |
|
50 |
std::wcout << L"checking mouse presence" << std::endl; |
|
51 |
try { |
|
52 |
getMouse(); |
|
53 |
return true; |
|
54 |
} catch (const HIDException& e) { |
|
55 |
logException(e); |
|
56 |
return false; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
Q_PROPERTY(QString deviceName READ deviceName) |
|
61 |
QString deviceName() { |
|
62 |
std::wcout << L"reading mouse name" << std::endl; |
|
63 |
try { |
|
64 |
return QString::fromStdWString(getMouse().getProductName()); |
|
65 |
} catch (HIDException& e) { |
|
66 |
logException(e); |
|
67 |
return QString(); |
|
68 |
} |
|
69 |
} |
|
70 |
||
29
361687fe303a
add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
71 |
void configure(bool liftOffDetection, bool smartScrolling, bool remapWheelPress, bool remapGestureButton, int frequency) { |
12 | 72 |
std::wcout << L"configuring mouse" << std::endl; |
73 |
try { |
|
74 |
CadMouseConfig config; |
|
75 |
config.setLiftOffDetection(liftOffDetection); |
|
76 |
config.setSmartScrolling(smartScrolling); |
|
29
361687fe303a
add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
77 |
config.setWheelPressRemapped(remapWheelPress); |
361687fe303a
add two new options: 1) remap wheel button 2) remap gesture button
František Kučera <franta-hg@frantovo.cz>
parents:
26
diff
changeset
|
78 |
config.setRemapGestureButton(remapGestureButton); |
12 | 79 |
config.setFrequency(Common::parseFrequency(std::to_wstring(frequency))); |
80 |
getMouse().sendFeatureReport(config.serialize()); |
|
81 |
} catch (HIDException& e) { |
|
82 |
logException(e); |
|
83 |
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage())); |
|
84 |
} catch (CLIException& e) { |
|
85 |
sendErrorReply(QDBusError::ErrorType::Failed, QString::fromStdWString(e.getMessage())); |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
}; |