mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-30 21:21:10 +00:00 
			
		
		
		
	Go through all event devices, not just event[0-32]
There are no guarantees that joypads are in event0-event32 range. Some devices, such as laptops with detachable keyboards and wacom can reserve events all the way up to 32. Some udev rules with e.g. custom controller firmwares may load the device as /dev/input/eventX, where X is greater than 32. This patch uses POSIX dirent to enumerate the event devices, so entries outside 0-32 range are not skipped.
This commit is contained in:
		
							parent
							
								
									c5c9517e1e
								
							
						
					
					
						commit
						01c030f9b7
					
				
					 1 changed files with 15 additions and 4 deletions
				
			
		|  | @ -32,6 +32,7 @@ | ||||||
| 
 | 
 | ||||||
| #include "joypad_linux.h" | #include "joypad_linux.h" | ||||||
| 
 | 
 | ||||||
|  | #include <dirent.h> | ||||||
| #include <errno.h> | #include <errno.h> | ||||||
| #include <fcntl.h> | #include <fcntl.h> | ||||||
| #include <linux/input.h> | #include <linux/input.h> | ||||||
|  | @ -183,14 +184,24 @@ void JoypadLinux::monitor_joypads() { | ||||||
| 		{ | 		{ | ||||||
| 			MutexLock lock(joy_mutex); | 			MutexLock lock(joy_mutex); | ||||||
| 
 | 
 | ||||||
| 			for (int i = 0; i < 32; i++) { | 			DIR *input_directory; | ||||||
|  | 			input_directory = opendir("/dev/input"); | ||||||
|  | 			if (input_directory) { | ||||||
|  | 				struct dirent *current; | ||||||
| 				char fname[64]; | 				char fname[64]; | ||||||
| 				sprintf(fname, "/dev/input/event%d", i); | 
 | ||||||
|  | 				while ((current = readdir(input_directory)) != NULL) { | ||||||
|  | 					if (strncmp(current->d_name, "event", 5) != 0) { | ||||||
|  | 						continue; | ||||||
|  | 					} | ||||||
|  | 					sprintf(fname, "/dev/input/%.*s", 16, current->d_name); | ||||||
| 					if (attached_devices.find(fname) == -1) { | 					if (attached_devices.find(fname) == -1) { | ||||||
| 						open_joypad(fname); | 						open_joypad(fname); | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  | 			closedir(input_directory); | ||||||
|  | 		} | ||||||
| 		usleep(1000000); // 1s
 | 		usleep(1000000); // 1s
 | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jari Ronkainen
						Jari Ronkainen