summaryrefslogtreecommitdiff
path: root/lib/sway/node.vala
diff options
context:
space:
mode:
authornoname <[email protected]>2025-03-03 21:53:09 +1100
committernoname <[email protected]>2025-03-03 22:06:48 +1100
commite9a47074e874aaa08fa781375f00930783ba99a8 (patch)
tree32880009318fd890015c5038b2a2fd4eded46601 /lib/sway/node.vala
parentf1df814f2e5795330615c00e5d8069325a3629bf (diff)
nodes properties and workspace events
Diffstat (limited to 'lib/sway/node.vala')
-rw-r--r--lib/sway/node.vala81
1 files changed, 65 insertions, 16 deletions
diff --git a/lib/sway/node.vala b/lib/sway/node.vala
index c3777f3..1243854 100644
--- a/lib/sway/node.vala
+++ b/lib/sway/node.vala
@@ -3,23 +3,50 @@ namespace AstalSway {
ROOT,
WORKSPACE,
CONTAINER,
- CLIENT,
- MONITOR
+ WINDOW,
+ OUTPUT
+ }
+
+ public struct Rectangle {
+ public static Rectangle from_json(Json.Object obj) {
+ return Rectangle() {
+ x = (int)obj.get_int_member("x"),
+ y = (int)obj.get_int_member("y"),
+ width = (int)obj.get_int_member("width"),
+ height = (int)obj.get_int_member("height"),
+ };
+
+ }
+
+ public int x;
+ public int y;
+ public int width;
+ public int height;
}
public class Node : Object {
public int id {get; private set; }
public bool focused { get; private set; }
- public string name;
- public string layout;
- public NodeType type;
+ public bool urgent { get; private set; }
+ public string name { get; private set; }
+ public string layout { get; private set; }
+ public string orientation { get; private set; }
+ public float? percent { get; private set; }
+ public Rectangle rect { get; private set; }
+ public Rectangle window_rect { get; private set; }
+ public Rectangle deco_rect { get; private set; }
+ public NodeType node_type {get; protected set;}
+
public weak Node parent;
- private HashTable<int, Node> _nodes =
- new HashTable<int, Node>(i => i, (a,b) => a==b);
- public List<weak Node> nodes { owned get { return _nodes.get_values(); } }
+ public List<weak Node> nodes;
protected Json.Object data;
+
+ private static HashTable<int, Node> _temp_nodes =
+ new HashTable<int, Node>(i => i, (a,b) => a==b);
+ internal static HashTable<int, Node> _all_nodes =
+ new HashTable<int, Node>(i => i, (a,b) => a==b);
public static Node? build(Json.Object obj) {
if (obj == null) {
@@ -28,18 +55,31 @@ namespace AstalSway {
switch (obj.get_string_member("type")) {
case "workspace":
var ws = new Workspace();
- ws.sync(obj);
return ws as Node;
default:
var node = new Node();
- node.sync(obj);
return node;
break;
}
return null;
}
+
+ internal static async void sync_tree() {
+ var str = yield Sway.get_default().message_async(PayloadType.MESSAGE_GET_TREE, "");
+ var obj = Json.from_string(str).get_object();
+ if (obj == null) {
+ return;
+ }
+
+ Node root = build(obj);
+ _temp_nodes = new HashTable<int, Node>(i => i, (a,b) => a==b);
+ root.sync(obj);
+ _temp_nodes.insert(root.id, root);
+ _all_nodes = _temp_nodes;
+
+ }
internal virtual void sync(Json.Object obj) {
if (obj == null) {
@@ -48,30 +88,39 @@ namespace AstalSway {
data = obj;
id = (int)obj.get_int_member("id");
name = obj.get_string_member("name");
- focused = obj.get_boolean_member("focused");
+ orientation = obj.get_string_member("orientation");
layout = obj.get_string_member("layout");
+ focused = obj.get_boolean_member("focused");
+ urgent = obj.get_boolean_member("urgent");
+ rect = Rectangle.from_json(obj.get_object_member("rect"));
+ window_rect = Rectangle.from_json(obj.get_object_member("window_rect"));
+ deco_rect = Rectangle.from_json(obj.get_object_member("deco_rect"));
var arr = obj.get_array_member("nodes");
+ var arr2 = obj.get_array_member("floating_nodes");
sync_nodes(arr);
+ sync_nodes(arr2);
+
}
private void sync_nodes(Json.Array arr) {
- var new_nodes = new HashTable<int, Node>(i => i, (a,b) => a==b);
+ var new_nodes = new List<weak Node> ();
foreach (var item in arr.get_elements()) {
var obj = item.get_object();
int id = (int)obj.get_int_member("id");
- var node = _nodes.get(id);
+ var node = _all_nodes.get(id);
if (node == null) {
node = Node.build(obj);
}
- new_nodes.insert(id, node);
+ new_nodes.append(node);
+ _temp_nodes.insert(id, node);
node.sync(obj);
}
-
- _nodes = new_nodes;
+
+ nodes = (owned) new_nodes;
}
}
}