1717
1818i32 mouse = -1 ;
1919bool kernel = KernelModuleActive();
20+ std::vector<std::pair<std::string, std::string>> input_devices;
21+ std::pair<std::string, std::string> active_device;
2022
2123std::vector<bool > HexToReversedBinary (const char hex_char) {
2224 int value = 0 ;
@@ -82,6 +84,24 @@ std::vector<bool> DecodeCapabilities(const std::string &filename) {
8284 return binary_out;
8385}
8486
87+ void ChangeMouseDevice (const std::pair<std::string, std::string> &device) {
88+ mouse = open (device.first .c_str (), O_WRONLY);
89+ if (mouse < 0 ) {
90+ logging::Error (" could not open mouse" );
91+ const auto error = errno;
92+ if (error == EACCES) {
93+ const std::string username = getlogin ();
94+ logging::Error (
95+ " user is not in input group. please execute sudo usermod -aG input {}" , username);
96+ } else {
97+ logging::Error (" error code: " + std::to_string (error));
98+ }
99+ std::exit (1 );
100+ }
101+ logging::Info (" input device: {} ({})" , device.second , device.first );
102+ active_device = device;
103+ }
104+
85105void MouseInit () {
86106 if (KernelModuleActive ()) {
87107 mouse = open (" /dev/stealthmem" , O_RDWR);
@@ -92,6 +112,7 @@ void MouseInit() {
92112 return ;
93113 }
94114
115+ input_devices.clear ();
95116 for (const auto &entry : std::filesystem::directory_iterator (" /dev/input" )) {
96117 if (!entry.is_character_file ()) {
97118 continue ;
@@ -124,28 +145,15 @@ void MouseInit() {
124145 std::getline (name_file, device_name);
125146 name_file.close ();
126147
127- mouse = open (entry.path ().c_str (), O_WRONLY);
128- if (mouse < 0 ) {
129- logging::Error (" could not open mouse" );
130- const auto error = errno;
131- if (error == EACCES) {
132- const std::string username = getlogin ();
133- logging::Error (
134- " user is not in input group. please execute sudo usermod -aG input {}" ,
135- username);
136- } else {
137- logging::Error (" error code: " + std::to_string (error));
138- }
139- std::exit (1 );
140- }
141-
142- logging::Info (" found mouse: {} ({})" , device_name, event_name);
143- return ;
148+ input_devices.push_back ({entry.path (), device_name});
144149 }
145150
146- mouse = open (" /dev/null" , O_WRONLY);
147- logging::Warning (" no mouse device was found" );
148- std::exit (1 );
151+ if (input_devices.empty ()) {
152+ mouse = open (" /dev/null" , O_WRONLY);
153+ logging::Warning (" no mouse device was found" );
154+ std::exit (1 );
155+ }
156+ ChangeMouseDevice (input_devices[0 ]);
149157}
150158
151159void MouseQuit () {
0 commit comments