diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2025-01-18 19:19:49 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2025-01-18 19:19:49 +0100 |
commit | e41bc216b8e5f7a86f6690cf53e9f9ac4ec2e7b5 (patch) | |
tree | 7144f97eaa19f262c1196bc6354e0872b8832451 /eizoctl.c | |
parent | 034d1712e86293c00b8ffadabf35889ccb1fc5e5 (diff) | |
download | usb-drivers-e41bc216b8e5f7a86f6690cf53e9f9ac4ec2e7b5.tar.gz usb-drivers-e41bc216b8e5f7a86f6690cf53e9f9ac4ec2e7b5.tar.xz usb-drivers-e41bc216b8e5f7a86f6690cf53e9f9ac4ec2e7b5.zip |
eizoctl: also report USB-C from --input '?'
Diffstat (limited to 'eizoctl.c')
-rw-r--r-- | eizoctl.c | 63 |
1 files changed, 29 insertions, 34 deletions
@@ -895,7 +895,7 @@ eizo_get_input_ports(struct eizo_monitor *m, uint16_t *ports, size_t size) } static uint16_t -eizo_resolve_port(struct eizo_monitor *m, const char *port) +eizo_resolve_port_by_name(struct eizo_monitor *m, const char *port) { uint8_t usb_c_index = 0; if (eizo_port_by_name_in_group(port, g_port_names_usb_c, &usb_c_index)) { @@ -907,6 +907,28 @@ eizo_resolve_port(struct eizo_monitor *m, const char *port) return eizo_port_by_name(port); } +static char * +eizo_resolve_port_to_name(struct eizo_monitor *m, uint16_t port) +{ + // USB-C ports are a bit tricky, they only need to be /displayed/ as such. + struct eizo_profile_item *item = + &m->profile[EIZO_PROFILE_KEY_USB_C_INPUT_PORTS]; + + uint8_t usb_c = 0; + for (size_t u = 0; u < item->len / 2; u++) + if (port == peek_u16le(item->data + u * 2)) + usb_c = u + 1; + if (!usb_c) + return eizo_port_to_name(port); + + static char buffer[32] = ""; + if (usb_c == 1) + snprintf(buffer, sizeof buffer, "%s", g_port_names_usb_c[0]); + else + snprintf(buffer, sizeof buffer, "%s %u", g_port_names_usb_c[0], usb_c); + return buffer; +} + static bool eizo_set_input_port(struct eizo_monitor *m, uint16_t port) { @@ -1118,13 +1140,12 @@ run(int argc, char *argv[], print_fn output, print_fn error) } if (port) { uint16_t prev = 0; - uint16_t next = eizo_resolve_port(&m, port); + uint16_t next = eizo_resolve_port_by_name(&m, port); if (!eizo_get_input_port(&m, &prev)) { error("Failed to get input port: %s\n", m.error); } else if (!strcmp(port, "?")) { - // XXX: This does not report USB-C. output("%s %s: input: %s\n", - m.product, m.serial, eizo_port_to_name(prev)); + m.product, m.serial, eizo_resolve_port_to_name(&m, prev)); } else if (!next) { error("Failed to resolve port name: %s\n", port); } else { @@ -1283,21 +1304,9 @@ append_monitor(struct eizo_monitor *m, HMENU menu, UINT_PTR base) if (!ports[0]) ports[0] = current; - // USB-C ports are a bit tricky, they only need to be /displayed/ as such. - struct eizo_profile_item *item = - &m->profile[EIZO_PROFILE_KEY_USB_C_INPUT_PORTS]; for (size_t i = 0; ports[i]; i++) { - uint8_t usb_c = 0; - for (size_t u = 0; u < item->len / 2; u++) - if (ports[i] == peek_u16le(item->data + u * 2)) - usb_c = u + 1; - - if (!usb_c) - snwprintf(buf, sizeof buf, L"%s", eizo_port_to_name(ports[i])); - else if (usb_c == 1) - snwprintf(buf, sizeof buf, L"%s", g_port_names_usb_c[0]); - else - snwprintf(buf, sizeof buf, L"%s %u", g_port_names_usb_c[0], usb_c); + snwprintf(buf, sizeof buf, L"%s", + eizo_resolve_port_to_name(m, ports[i])); UINT flags = MF_STRING; if (ports[i] == current) @@ -1664,23 +1673,9 @@ message_error(const char *format, ...) if (!ports[0]) ports[0] = current; - // USB-C ports are a bit tricky, they only need to be /displayed/ as such. - struct eizo_profile_item *item = - &m.monitor->profile[EIZO_PROFILE_KEY_USB_C_INPUT_PORTS]; for (size_t i = 0; ports[i]; i++) { - uint8_t usb_c = 0; - for (size_t u = 0; u < item->len / 2; u++) - if (ports[i] == peek_u16le(item->data + u * 2)) - usb_c = u + 1; - - NSString *title = nil; - if (!usb_c) - title = [NSString stringWithUTF8String:eizo_port_to_name(ports[i])]; - else if (usb_c == 1) - title = [NSString stringWithUTF8String:g_port_names_usb_c[0]]; - else - title = [NSString stringWithFormat:@"%s %u", - g_port_names_usb_c[0], usb_c]; + NSString *title = [NSString stringWithUTF8String: + eizo_resolve_port_to_name(m.monitor, ports[i])]; NSMenuItem *inputPortItem = [[NSMenuItem alloc] initWithTitle:title action:@selector(setInputPort:) |