mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-01-31 01:13:04 +09:00
Fix controller hotplug not always working
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.7.0', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
project('gsr-ui', ['c', 'cpp'], version : '1.7.1', default_options : ['warning_level=2', 'cpp_std=c++17'], subproject_dir : 'depends')
|
||||
|
||||
if get_option('buildtype') == 'debug'
|
||||
add_project_arguments('-g3', language : ['c', 'cpp'])
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "gsr-ui"
|
||||
type = "executable"
|
||||
version = "1.7.0"
|
||||
version = "1.7.1"
|
||||
platforms = ["posix"]
|
||||
|
||||
[lang.cpp]
|
||||
|
||||
@@ -102,7 +102,8 @@ namespace gsr {
|
||||
close(event_fd);
|
||||
|
||||
for(int i = 0; i < num_poll_fd; ++i) {
|
||||
close(poll_fd[i].fd);
|
||||
if(poll_fd[i].fd > 0)
|
||||
close(poll_fd[i].fd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +222,9 @@ namespace gsr {
|
||||
if(i == event_index)
|
||||
goto done;
|
||||
|
||||
char dev_input_filepath[256];
|
||||
snprintf(dev_input_filepath, sizeof(dev_input_filepath), "/dev/input/js%d", extra_data[i].dev_input_id);
|
||||
fprintf(stderr, "Info: removed joystick: %s\n", dev_input_filepath);
|
||||
if(remove_poll_fd(i))
|
||||
--i; // This item was removed so we want to repeat the same index to continue to the next item
|
||||
|
||||
@@ -234,18 +238,13 @@ namespace gsr {
|
||||
goto done;
|
||||
} else if(i == hotplug_poll_index) {
|
||||
hotplug.process_event_data(poll_fd[i].fd, [&](HotplugAction hotplug_action, const char *devname) {
|
||||
char dev_input_filepath[1024];
|
||||
snprintf(dev_input_filepath, sizeof(dev_input_filepath), "/dev/%s", devname);
|
||||
switch(hotplug_action) {
|
||||
case HotplugAction::ADD: {
|
||||
// Cant open the /dev/input device immediately or it fails.
|
||||
// TODO: Remove this hack when a better solution is found.
|
||||
usleep(50 * 1000);
|
||||
add_device(dev_input_filepath);
|
||||
add_device(devname);
|
||||
break;
|
||||
}
|
||||
case HotplugAction::REMOVE: {
|
||||
if(remove_device(dev_input_filepath))
|
||||
if(remove_device(devname))
|
||||
--i; // This item was removed so we want to repeat the same index to continue to the next item
|
||||
break;
|
||||
}
|
||||
@@ -373,7 +372,9 @@ namespace gsr {
|
||||
if(index < 0 || index >= num_poll_fd)
|
||||
return false;
|
||||
|
||||
close(poll_fd[index].fd);
|
||||
if(poll_fd[index].fd > 0)
|
||||
close(poll_fd[index].fd);
|
||||
|
||||
for(int i = index + 1; i < num_poll_fd; ++i) {
|
||||
poll_fd[i - 1] = poll_fd[i];
|
||||
extra_data[i - 1] = extra_data[i];
|
||||
|
||||
@@ -59,10 +59,9 @@ namespace gsr {
|
||||
|
||||
/* TODO: This assumes SUBSYSTEM= is output before DEVNAME=, is that always true? */
|
||||
void Hotplug::parse_netlink_data(const char *line, const HotplugEventCallback &callback) {
|
||||
const char *at_symbol = strchr(line, '@');
|
||||
if(at_symbol) {
|
||||
event_is_add = strncmp(line, "add@", 4) == 0;
|
||||
event_is_remove = strncmp(line, "remove@", 7) == 0;
|
||||
if(strncmp(line, "ACTION=", 7) == 0) {
|
||||
event_is_add = strncmp(line+7, "add", 3) == 0;
|
||||
event_is_remove = strncmp(line+7, "remove", 6) == 0;
|
||||
subsystem_is_input = false;
|
||||
} else if(event_is_add || event_is_remove) {
|
||||
if(strcmp(line, "SUBSYSTEM=input") == 0)
|
||||
|
||||
Reference in New Issue
Block a user