Revision: 45528
http://sourceforge.net/p/vice-emu/code/45528
Author: compyx
Date: 2025-03-13 14:33:32 +0000 (Thu, 13 Mar 2025)
Log Message:
-----------
Joystick: log joystick registation with proper signular/plural nouns
Avoid things like "1 buttons", right-trim device names and limit names of
idiotic length (>255 chars) so the UI doesn't have to trim names.
Modified Paths:
--------------
branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
branches/compyx/joymap-001/vice/src/joyport/joystick.c
Modified: branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c
===================================================================
--- branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-13 08:34:04 UTC (rev 45527)
+++ branches/compyx/joymap-001/vice/src/arch/gtk3/joystickdrv/joystick_linux_evdev.c 2025-03-13 14:33:32 UTC (rev 45528)
@@ -422,21 +422,21 @@
for (i = 0; i < sd_result; i++) {
joystick_device_t *joydev;
- log_message(joy_evdev_log, "Possible device '%s'", namelist[i]->d_name);
+ //log_message(joy_evdev_log, "Possible device '%s'", namelist[i]->d_name);
joydev = scan_device(namelist[i]->d_name);
if (joydev != NULL) {
if (joydev->num_axes < 2u || joydev->num_buttons < 1u) {
/* reject device */
- log_message(joy_evdev_log,
- "Invalid geometry for %s: axes: %d, buttons: %d",
- joydev->name, joydev->num_axes, joydev->num_buttons);
+ //log_message(joy_evdev_log,
+ // "Invalid geometry for %s: axes: %d, buttons: %d",
+ // joydev->name, joydev->num_axes, joydev->num_buttons);
joystick_device_free(joydev);
} else {
- log_message(joy_evdev_log,
- "Adding device: %s [%04x:%04x] (%d axes, %d buttons)",
- joydev->name,
- (unsigned int)joydev->vendor, (unsigned int)joydev->product,
- joydev->num_axes, joydev->num_buttons);
+ //log_message(joy_evdev_log,
+ // "Adding device: %s [%04x:%04x] (%d axes, %d buttons)",
+ // joydev->name,
+ // (unsigned int)joydev->vendor, (unsigned int)joydev->product,
+ // joydev->num_axes, joydev->num_buttons);
if (!joystick_device_register(joydev)) {
log_message(joy_evdev_log,
Modified: branches/compyx/joymap-001/vice/src/joyport/joystick.c
===================================================================
--- branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-13 08:34:04 UTC (rev 45527)
+++ branches/compyx/joymap-001/vice/src/joyport/joystick.c 2025-03-13 14:33:32 UTC (rev 45528)
@@ -3309,6 +3309,26 @@
}
+/** \brief Right-trim name and limit to 255 chars max
+ *
+ * Right-trim name (at least one device reports a name with trailing spaces on
+ * Linux) and limit length to 255 characters to avoid bizarre behaviour in UIs.
+ *
+ * \param[in] joydev joystick device
+ */
+static void joystick_device_trim_name(joystick_device_t *joydev)
+{
+ char *p = joydev->name + strlen(joydev->name) - 1;
+
+ while (p >= joydev->name && isspace((unsigned int)*p)) {
+ *p-- = '\0';
+ }
+ /* limit name to 255 max to guard against weird broken names */
+ if (p - joydev->name + 1 > 255) {
+ joydev->name[255] = '\0';
+ }
+}
+
/** \brief Apply default minimal mapping to joystick device
*
* Map input for four directions and up to three fire buttons. If the device
@@ -3393,7 +3413,48 @@
return true;
}
+/** \brief Log registration of device
+ *
+ * Log message with proper singular/plural nouns for number of axes, buttons
+ * and hats.
+ *
+ * \param[in] joydev joystick device
+ */
+static void joy_log_registration(const joystick_device_t *joydev)
+{
+ char msg[1024];
+ int ret;
+ ret = snprintf(msg, sizeof msg,
+ "Registered device \"%s\" [%04x:%04x] (",
+ joydev->name, joydev->vendor, joydev->product);
+ if (joydev->num_axes == 1) {
+ strcpy(msg + ret, "1 axis, ");
+ ret += 8;
+ } else {
+ ret += snprintf(msg + ret, sizeof msg - (size_t)ret,
+ "%d axes, ", joydev->num_axes);
+ }
+
+ if (joydev->num_buttons == 1) {
+ strcpy(msg + ret, "1 button, ");
+ ret += 10;
+ } else {
+ ret += snprintf(msg + ret, sizeof msg - (size_t)ret,
+ "%d buttons, ", joydev->num_buttons);
+ }
+
+ if (joydev->num_hats == 1) {
+ strcpy(msg + ret, "1 hat)");
+ } else {
+ snprintf(msg + ret, sizeof msg - (size_t) ret,
+ "%d hats)", joydev->num_hats);
+ }
+
+ log_message(joy_log, "%s", msg);
+}
+
+
/** \brief Register joystick device
*
* Add \a joydev to the list of available joystick devices.
@@ -3419,11 +3480,14 @@
sizeof *joystick_devices * max_joystick_devices);
}
+ joystick_device_trim_name(joydev);
joystick_device_apply_default_mapping(joydev);
joystick_devices[num_joystick_devices] = joydev;
joystick_devices[++num_joystick_devices] = NULL;
+ /* log device registration */
+ joy_log_registration(joydev);
return true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|