diff options
author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2024-04-22 00:35:53 -0300 |
---|---|---|
committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2024-04-22 00:35:53 -0300 |
commit | 5f01c706267c595de92406a32e7f31ef5056c2d0 (patch) | |
tree | d1e74ef54efc41ada622900fe3e2a50dee44a237 /modules/devices/inputdevices.c | |
parent | 09fcc751ef158898c315ebc9299a0fa3a722d914 (diff) |
New upstream version 2.0.3preupstream/2.0.3pre
Diffstat (limited to 'modules/devices/inputdevices.c')
-rw-r--r-- | modules/devices/inputdevices.c | 199 |
1 files changed, 115 insertions, 84 deletions
diff --git a/modules/devices/inputdevices.c b/modules/devices/inputdevices.c index cf1728a9..301641d4 100644 --- a/modules/devices/inputdevices.c +++ b/modules/devices/inputdevices.c @@ -1,10 +1,10 @@ /* * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> + * Copyright (C) 2003-2006 L. A. F. Pereira <l@tia.mat.br> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. + * the Free Software Foundation, version 2 or later. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,6 +20,7 @@ #include "hardinfo.h" #include "devices.h" +#include "usb_util.h" gchar *input_icons = NULL; @@ -27,113 +28,143 @@ static struct { char *name; char *icon; } input_devices[] = { + { NULL, "module.png" }, // UNKNOWN { "Keyboard", "keyboard.png" }, { "Joystick", "joystick.png" }, { "Mouse", "mouse.png" }, - { "Speaker", "audio.png" }, - { "Unknown", "module.png" }, + { "Speaker", "audio.png" }, + { "Audio", "audio.png" } }; +// source: https://elixir.bootlin.com/linux/v5.9/source/include/uapi/linux/input.h#L251 +static const gchar *bus_types[] = { + NULL, "PCI", "ISA PnP", "USB", // 0x0 - 0x3 + "HIL", "Bluetooth", "Virtual", NULL, // 0x4 - 0x7 + NULL, NULL, NULL, NULL, // 0x8 - 0xB + NULL, NULL, NULL, NULL, // 0xC - 0xF + "ISA", "i8042", "XT Keyboard bus", "RS232", // 0x10 - 0x13 + "Game port", "Parallel port", "Amiga bus", "ADB", // 0x14 - 0x17 + "I²C", "HOST", "GSC", "Atari bus", // 0x18 - 0x1B + "SPI", "RMI", "CEC", "Intel ISHTP" // 0x1C - 0x1F +}; + +#define UNKWNIFNULL(f) ((f) ? f : _("(Unknown)")) +#define EMPTYIFNULL(f) ((f) ? f : "") + void __scan_input_devices(void) { FILE *dev; gchar buffer[1024]; + vendor_list vl = NULL; gchar *tmp, *name = NULL, *phys = NULL; + gchar *vendor_str = NULL, *product_str = NULL, *vendor_tags = NULL; gint bus = 0, vendor = 0, product = 0, version = 0; + const gchar *bus_str = NULL; int d = 0, n = 0; dev = fopen("/proc/bus/input/devices", "r"); if (!dev) - return; + return; if (input_list) { moreinfo_del_with_prefix("DEV:INP"); - g_free(input_list); - g_free(input_icons); + g_free(input_list); + g_free(input_icons); } input_list = g_strdup(""); input_icons = g_strdup(""); while (fgets(buffer, sizeof(buffer), dev)) { - tmp = buffer; - - switch (*tmp) { - case 'N': - tmp = strreplacechr(tmp + strlen("N: Name="), "=", ':'); - name = g_strdup(tmp); - remove_quotes(name); - break; - case 'P': - phys = g_strdup(tmp + strlen("P: Phys=")); - break; - case 'I': - sscanf(tmp, "I: Bus=%x Vendor=%x Product=%x Version=%x", - &bus, &vendor, &product, &version); - break; - case 'H': - if (strstr(tmp, "kbd")) - d = 0; //INPUT_KEYBOARD; - else if (strstr(tmp, "js")) - d = 1; //INPUT_JOYSTICK; - else if (strstr(tmp, "mouse")) - d = 2; //INPUT_MOUSE; - else - d = 4; //INPUT_UNKNOWN; - break; - case '\n': - if (name && strstr(name, "PC Speaker")) { - d = 3; // INPUT_PCSPKR - } - - tmp = g_strdup_printf("INP%d", ++n); - input_list = h_strdup_cprintf("$%s$%s=\n", - input_list, - tmp, name); - input_icons = h_strdup_cprintf("Icon$%s$%s=%s\n", - input_icons, - tmp, name, - input_devices[d].icon); - - const gchar *v_url = (gchar*)vendor_get_url(name); - const gchar *v_name = (gchar*)vendor_get_name(name); - gchar *v_str = NULL; - if (v_url != NULL) - v_str = g_strdup_printf("[0x%x] %s (%s)", vendor, v_name, v_url); - else - v_str = g_strdup_printf("0x%x", vendor); - v_str = hardinfo_clean_value(v_str, 1); - name = hardinfo_clean_value(name, 1); - - gchar *strhash = g_strdup_printf("[%s]\n" - /* Name */ "%s=%s\n" - /* Type */ "%s=%s\n" - /* Bus */ "%s=0x%x\n" - /* Vendor */ "%s=%s\n" - /* Product */"%s=0x%x\n" - /* Version */"%s=0x%x\n", - _("Device Information"), - _("Name"), name, - _("Type"), input_devices[d].name, - _("Bus"), bus, - _("Vendor"), v_str, - _("Product"), product, - _("Version"), version ); - - if (phys && phys[1] != 0) { - strhash = h_strdup_cprintf("%s=%s\n", strhash, _("Connected to"), phys); + tmp = buffer; + + switch (*tmp) { + case 'N': + tmp = strreplacechr(tmp + strlen("N: Name="), "=", ':'); + name = g_strdup(tmp); + remove_quotes(name); + break; + case 'P': + phys = g_strdup(tmp + strlen("P: Phys=")); + break; + case 'I': + sscanf(tmp, "I: Bus=%x Vendor=%x Product=%x Version=%x", + &bus, &vendor, &product, &version); + break; + case 'H': + if (strstr(tmp, "kbd")) + d = 1; //INPUT_KEYBOARD; + else if (strstr(tmp, "js")) + d = 2; //INPUT_JOYSTICK; + else if (strstr(tmp, "mouse")) + d = 3; //INPUT_MOUSE; + else + d = 0; //INPUT_UNKNOWN; + break; + case '\n': + if (name && strstr(name, "PC Speaker")) { + d = 4; // INPUT_PCSPKR + } + if (d == 0 && g_strcmp0(phys, "ALSA")) { + d = 5; // INPUT_AUDIO + } + + if (vendor > 0 && product > 0 && g_str_has_prefix(phys, "usb-")) { + usb_lookup_ids_vendor_product_str(vendor, product, &vendor_str, &product_str); + } + + if (bus >= 0 && (guint)bus < sizeof(bus_types) / sizeof(gchar*)) { + bus_str = bus_types[bus]; + } + + vl = vendor_list_remove_duplicates_deep(vendors_match(name, vendor_str, NULL)); + vendor_tags = vendor_list_ribbon(vl, params.fmt_opts); + + tmp = g_strdup_printf("INP%d", ++n); + input_list = h_strdup_cprintf("$%s$%s=%s|%s\n", + input_list, + tmp, name, EMPTYIFNULL(vendor_tags), + EMPTYIFNULL(input_devices[d].name)); + input_icons = h_strdup_cprintf("Icon$%s$%s=%s\n", + input_icons, + tmp, name, + input_devices[d].icon); + + gchar *strhash = g_strdup_printf("[%s]\n" + /* Name */ "$^$%s=%s\n" + /* Type */ "%s=%s\n" + /* Bus */ "%s=[0x%x] %s\n" + /* Vendor */ "$^$%s=[0x%x] %s\n" + /* Product */"%s=[0x%x] %s\n" + /* Version */"%s=0x%x\n", + _("Device Information"), + _("Name"), name, + _("Type"), UNKWNIFNULL(input_devices[d].name), + _("Bus"), bus, UNKWNIFNULL(bus_str), + _("Vendor"), vendor, UNKWNIFNULL(vendor_str), + _("Product"), product, UNKWNIFNULL(product_str), + _("Version"), version ); + + if (phys && phys[1] != 0) { + strhash = h_strdup_cprintf("%s=%s\n", strhash, _("Connected to"), phys); + } + + if (phys && strstr(phys, "ir")) { + strhash = h_strdup_cprintf("%s=%s\n", strhash, _("InfraRed port"), _("Yes") ); + } + + moreinfo_add_with_prefix("DEV", tmp, strhash); + g_free(tmp); + g_free(phys); + g_free(name); + g_free(vendor_str); + g_free(vendor_tags); + g_free(product_str); + bus_str = NULL; + vendor_str = NULL; + product_str = NULL; + vendor_tags = NULL; } - - if (phys && strstr(phys, "ir")) { - strhash = h_strdup_cprintf("%s=%s\n", strhash, _("InfraRed port"), _("Yes") ); - } - - moreinfo_add_with_prefix("DEV", tmp, strhash); - g_free(tmp); - g_free(v_str); - g_free(phys); - g_free(name); - } } fclose(dev); |