diff --git a/src/swayfocus.cr b/src/swayfocus.cr index 06c900e..35a19c7 100644 --- a/src/swayfocus.cr +++ b/src/swayfocus.cr @@ -3,17 +3,32 @@ require "option_parser" version = "0.1" +struct Nil + def includes? ( a : String) + false + end +end + class Window - JSON.mapping({ - id: UInt32, - name: String, - wtype: {type: String, key: "type"}, - app_id: {type: String, default: ""}, - wclass: {type: String, key: "class", default: ""}, - marks: {type: Array(String), default: [] of String}, - nodes: {type: Array(Window), default: [] of Window}, - focused: {type: Bool, default: false} - }) + include JSON::Serializable + + property id : UInt32 = 0 + + @[JSON::Field(emit_null: true)] + property name : String? + + @[JSON::Field(key: "type")] + property wtype : String = "" + + property app_id : String = "" + + @[JSON::Field(key: "class")] + property wclass : String = "" + + property marks : Array(String) = [] of String + property nodes : Array(Window) = [] of Window + + property focused : Bool = false def clear_nodes @nodes = [] of Window @@ -23,7 +38,7 @@ end def node_loop (root : Window) list = [] of Window root.nodes.each do |node| - if node.wtype == "con" + if node.wtype == "con" && !node.name.nil? list << node elsif !node.nodes.empty? list.concat node_loop node