From db18e2252fdc6c1e47cfbd15c5d1fdd943fa794f Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Tue, 17 Dec 2024 01:03:43 +0900 Subject: [PATCH] Fix some build warnings (#71) * Fix some build warnings * Decent log message --- src/Backend/DeviceManagerWayland.vala | 30 +++++++++++++++------------ src/Backend/WacomToolMap.vala | 2 +- src/MainPage.vala | 9 +++++++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Backend/DeviceManagerWayland.vala b/src/Backend/DeviceManagerWayland.vala index 6ce8efb..202eba1 100644 --- a/src/Backend/DeviceManagerWayland.vala +++ b/src/Backend/DeviceManagerWayland.vala @@ -21,14 +21,17 @@ public class Wacom.Backend.DeviceManagerWayland : DeviceManager { private Gee.HashMap? devices = null; private GUdev.Client? client = null; - // Keep in same order as types in Device.vala - const string[] UDEV_IDS = { - "ID_INPUT_MOUSE", - "ID_INPUT_KEYBOARD", - "ID_INPUT_TOUCHPAD", - "ID_INPUT_TABLET", - "ID_INPUT_TOUCHSCREEN", - "ID_INPUT_TABLET_PAD", + private struct UdevIDTable { + string udev_id; + Device.DeviceType device_type; + } + const UdevIDTable[] UDEV_ID_TABLE = { + { "ID_INPUT_MOUSE", Device.DeviceType.MOUSE }, + { "ID_INPUT_KEYBOARD", Device.DeviceType.KEYBOARD }, + { "ID_INPUT_TOUCHPAD", Device.DeviceType.TOUCHPAD }, + { "ID_INPUT_TABLET", Device.DeviceType.TABLET }, + { "ID_INPUT_TOUCHSCREEN", Device.DeviceType.TOUCHSCREEN }, + { "ID_INPUT_TABLET_PAD", Device.DeviceType.PAD }, }; public DeviceManagerWayland () { @@ -95,9 +98,9 @@ public class Wacom.Backend.DeviceManagerWayland : DeviceManager { private static Device.DeviceType get_udev_device_type (GUdev.Device device) { Device.DeviceType type = 0; - for (int i = 0; i < UDEV_IDS.length; i++) { - if (device.get_property_as_boolean (UDEV_IDS[i])) { - type |= (1 << i); + for (int i = 0; i < UDEV_ID_TABLE.length; i++) { + if (device.get_property_as_boolean (UDEV_ID_TABLE[i].udev_id)) { + type |= UDEV_ID_TABLE[i].device_type; } } @@ -145,11 +148,12 @@ public class Wacom.Backend.DeviceManagerWayland : DeviceManager { } public override Device? lookup_gdk_device (Gdk.Device device) { - if (!(device is Gdk.Wayland.Device)) { + Gdk.Wayland.Device? wayland_device = (device as Gdk.Wayland.Device); + if (wayland_device == null) { return null; } - var node_path = (device as Gdk.Wayland.Device).get_node_path (); + var node_path = wayland_device.get_node_path (); if (node_path == null) { return null; } diff --git a/src/Backend/WacomToolMap.vala b/src/Backend/WacomToolMap.vala index d05ffd4..2d83506 100644 --- a/src/Backend/WacomToolMap.vala +++ b/src/Backend/WacomToolMap.vala @@ -225,7 +225,7 @@ public class Wacom.Backend.WacomToolMap : GLib.Object { } } - public Gee.ArrayList list_tools (Backend.Device device) { + public Gee.ArrayList list_tools (Backend.Device device) throws WacomException { var styli = new Gee.ArrayList (); var key = "%s:%s".printf (device.vendor_id, device.product_id); diff --git a/src/MainPage.vala b/src/MainPage.vala index fbb2feb..50a3728 100644 --- a/src/MainPage.vala +++ b/src/MainPage.vala @@ -88,7 +88,14 @@ public class Wacom.MainPage : Switchboard.SettingsPage { return; } - var tools = tool_map.list_tools (d); + Gee.ArrayList tools; + try { + tools = tool_map.list_tools (d); + } catch (WacomException e) { + warning ("Failed to list tools: %s", e.message); + return; + } + if (tools.size > 0) { stylus_view.set_device (tools[0]); stylus_stack.visible_child = stylus_view;