swayipc-rs icon indicating copy to clipboard operation
swayipc-rs copied to clipboard

Enums instead of Strings

Open ModProg opened this issue 2 years ago • 2 comments

What do you think about replacing the strings for things like layout with enums?

This would allow a better typed experience writing code for this. The only issue I see is, that there might be an invalid variant returned, but that could be solved by adding a fallback to the enum like so:

enum WorkspaceLayout {
  Splith,
  Splitv,
  Stacked,
  Tabbed,
  Other(String)
}

ModProg avatar Nov 04 '22 11:11 ModProg

Well after looking a little further seems like only the on Workspace there is no Enum for the layout.

ModProg avatar Nov 04 '22 15:11 ModProg

Yep, this is definitely an oversight on my part when I added the layout in 8af9ba21251699699fb9c510b58d383beb824342 😅 Looking at the relevant section in sway's ipc-json.c the ipc_json_layout_description function is called which matches the NodeLayout enum.

JayceFayne avatar Nov 21 '22 21:11 JayceFayne