hyprland-community / hyprland-rs

An unofficial rust wrapper for hyprland's IPC [maintainers=@yavko,@cyrinux]
Other
252 stars 55 forks source link

Fix TabletBelongsTo deserialization #254

Closed sij1nk closed 3 months ago

sij1nk commented 3 months ago

Fixes #253

In the output of hyprctl -j devices, .tablets[].belongsTo is an object, which we try to deserialize into the TabletBelongsTo enum. However, this JSON object is just a "flat" object, containing the fields of one of the enum variants, without a tag specifying which variant it is. So we must use #[serde(untagged)] to correctly deserialize it


edit: technically there is a tag: the type field in the parent object:

{
    "address": "0x627fa3b386f0",
    "type": "tabletPad",                     <--
    "belongsTo": {
      "address": "0x0",
      "name": ""
    }
  },

Lmk if this solution is acceptable or if should instead take that type field into account (practically I don't think there's a difference)