Input/Qt: Check if gui callbacks are nullptr

This commit is contained in:
Megamouse 2020-07-04 13:18:45 +02:00
commit f1b1c9053c
3 changed files with 47 additions and 18 deletions

View file

@ -328,7 +328,11 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
const auto status = update_connection(device); const auto status = update_connection(device);
if (status == connection::disconnected) if (status == connection::disconnected)
return fail_callback(pad_id); {
if (fail_callback)
fail_callback(pad_id);
return;
}
else if (status == connection::no_data) else if (status == connection::no_data)
return; return;
@ -373,10 +377,13 @@ void PadHandlerBase::get_next_button_press(const std::string& pad_id, const pad_
const auto preview_values = get_preview_values(data); const auto preview_values = get_preview_values(data);
const auto battery_level = get_battery_level(pad_id); const auto battery_level = get_battery_level(pad_id);
if (callback)
{
if (pressed_button.first > 0) if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, pad_id, battery_level, preview_values); return callback(pressed_button.first, pressed_button.second, pad_id, battery_level, preview_values);
else else
return callback(0, "", pad_id, battery_level, preview_values); return callback(0, "", pad_id, battery_level, preview_values);
}
return; return;
} }

View file

@ -281,7 +281,11 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
// Get our evdev device // Get our evdev device
auto device = get_evdev_device(padId); auto device = get_evdev_device(padId);
if (!device || device->device == nullptr) if (!device || device->device == nullptr)
return fail_callback(padId); {
if (fail_callback)
fail_callback(padId);
return;
}
libevdev* dev = device->device; libevdev* dev = device->device;
// Try to query the latest event from the joystick. // Try to query the latest event from the joystick.
@ -320,7 +324,11 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
// return if nothing new has happened. ignore this to get the current state for blacklist // return if nothing new has happened. ignore this to get the current state for blacklist
if (!get_blacklist && ret < 0) if (!get_blacklist && ret < 0)
return callback(0, "", padId, 0, preview_values); {
if (callback)
callback(0, "", padId, 0, preview_values);
return;
}
std::pair<u16, std::string> pressed_button = { 0, "" }; std::pair<u16, std::string> pressed_button = { 0, "" };
@ -401,11 +409,14 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con
return; return;
} }
if (callback)
{
if (pressed_button.first > 0) if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values); return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else else
return callback(0, "", padId, 0, preview_values); return callback(0, "", padId, 0, preview_values);
} }
}
// https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp // https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp
// https://github.com/reicast/reicast-emulator/blob/master/core/linux-dist/evdev.cpp // https://github.com/reicast/reicast-emulator/blob/master/core/linux-dist/evdev.cpp

View file

@ -182,7 +182,11 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
blacklist.clear(); blacklist.clear();
if (!Init()) if (!Init())
return fail_callback(padId); {
if (fail_callback)
fail_callback(padId);
return;
}
static std::string cur_pad = ""; static std::string cur_pad = "";
static int id = -1; static int id = -1;
@ -194,7 +198,9 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
if (id < 0) if (id < 0)
{ {
input_log.error("MMJOY get_next_button_press for device [%s] failed with id = %d", padId, id); input_log.error("MMJOY get_next_button_press for device [%s] failed with id = %d", padId, id);
return fail_callback(padId); if (fail_callback)
fail_callback(padId);
return;
} }
} }
@ -210,7 +216,9 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
{ {
case JOYERR_UNPLUGGED: case JOYERR_UNPLUGGED:
{ {
return fail_callback(padId); if (fail_callback)
fail_callback(padId);
return;
} }
case JOYERR_NOERROR: case JOYERR_NOERROR:
{ {
@ -309,10 +317,13 @@ void mm_joystick_handler::get_next_button_press(const std::string& padId, const
preview_values[5] = data[find_key(buttons[9])] - data[find_key(buttons[8])]; preview_values[5] = data[find_key(buttons[9])] - data[find_key(buttons[8])];
} }
if (callback)
{
if (pressed_button.first > 0) if (pressed_button.first > 0)
return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values); return callback(pressed_button.first, pressed_button.second, padId, 0, preview_values);
else else
return callback(0, "", padId, 0, preview_values); return callback(0, "", padId, 0, preview_values);
}
break; break;
} }