summaryrefslogtreecommitdiff
path: root/lib/sway/sway.vala
diff options
context:
space:
mode:
authornoname <[email protected]>2025-03-06 17:49:33 +1100
committernoname <[email protected]>2025-03-06 18:49:02 +1100
commitf89b080e57d8284e197de9236101a7df266219a9 (patch)
treef01f085ebb301fb54acbb797303992e48be4441a /lib/sway/sway.vala
parent90019b99b671664855c1c53a30da39ca572f4a0e (diff)
implement outputs
Diffstat (limited to 'lib/sway/sway.vala')
-rw-r--r--lib/sway/sway.vala70
1 files changed, 60 insertions, 10 deletions
diff --git a/lib/sway/sway.vala b/lib/sway/sway.vala
index e7228c3..adcb0d9 100644
--- a/lib/sway/sway.vala
+++ b/lib/sway/sway.vala
@@ -31,6 +31,7 @@ namespace AstalSway {
}
public Workspace focused_workspace;
+ public Output focused_output;
public Container? focused_container;
private static HashTable<int, Node> _nodes =
@@ -40,8 +41,11 @@ namespace AstalSway {
private HashTable<string, Workspace> _workspaces =
new HashTable<string, Workspace>(str_hash, str_equal);
+ private HashTable<string, Output> _outputs =
+ new HashTable<string, Output>(str_hash, str_equal);
public List<weak Workspace> workspaces { owned get { return _workspaces.get_values(); } }
+ public List<weak Output> outputs { owned get { return _outputs.get_values(); } }
public List<weak Window> windows { owned get {
var arr = new List<weak Window>();
foreach (var node in nodes) {
@@ -49,11 +53,11 @@ namespace AstalSway {
arr.append(node as Window);
}
}
-
return arr;
} }
public Workspace get_workspace(string name) { return _workspaces.get(name); }
+ public Output get_output(string name) { return _outputs.get(name); }
public Node get_node(int id) { return _nodes.get(id); }
~Sway() {
@@ -77,20 +81,26 @@ namespace AstalSway {
public void run_command(string command) {
message_async.begin(PayloadType.MESSAGE_RUN_COMMAND, command,
(_, res) => {
- var obj = Json.from_string(message_async.end(res)).get_object();
- if (!obj.get_boolean_member("success")) {
- critical("Command error: %s", obj.get_string_member("error"));
+ var arr = Json.from_string(message_async.end(res)).get_array();
+ foreach (var item in arr.get_elements()) {
+ var obj = item.get_object();
+ if (!obj.get_boolean_member("success")) {
+ critical("Command error: %s", obj.get_string_member("error"));
+ }
}
}
);
}
- public async void sync() {
+ public async void sync_tree() {
yield Node.sync_tree();
_nodes = Node._all_nodes;
var new_workspaces = new HashTable<string, Workspace>(str_hash, str_equal);
+ var new_outputs = new HashTable<string, Output>(str_hash, str_equal);
+
+ // It's possible that there's no focused container
Container? new_focused_container = null;
foreach (var node in nodes) {
@@ -98,22 +108,58 @@ namespace AstalSway {
case NodeType.WORKSPACE:
var ws = node as Workspace;
new_workspaces.insert(ws.name, ws);
- if (ws.focused) {
- focused_workspace = ws;
- }
break;
case NodeType.CONTAINER:
- var con = node as Container;
+ case NodeType.WINDOW:
+ var con = node as Container;
if (con.focused) {
new_focused_container = con;
}
break;
+ case NodeType.OUTPUT:
+ var output = node as Output;
+ new_outputs.insert(output.name, output);
+ break;
}
}
+ _outputs = new_outputs;
+ _workspaces= new_workspaces;
focused_container = new_focused_container;
+ yield sync_workspaces();
+ yield sync_outputs();
}
+ private async void sync_workspaces() {
+ var res = yield message_async(PayloadType.MESSAGE_GET_WORKSPACES, "");
+ var arr = Json.from_string(res).get_array();
+ foreach (var item in arr.get_elements()) {
+ var obj = item.get_object();
+ var ws = get_workspace(obj.get_string_member("name"));
+ if (ws != null) {
+ ws.sync_workspace(obj);
+ if (ws.focused) {
+ focused_workspace = ws;
+ }
+ }
+ }
+ }
+
+ private async void sync_outputs() {
+ var res = yield message_async(PayloadType.MESSAGE_GET_OUTPUTS, "");
+ var arr = Json.from_string(res).get_array();
+ foreach (var item in arr.get_elements()) {
+ var obj = item.get_object();
+ var output = get_output(obj.get_string_member("name"));
+ if (output != null) {
+ output.sync_output(obj);
+ if (output.focused) {
+ focused_output = output;
+ }
+ }
+ }
+ }
+
private async void subscribe() {
if (subscribe_socket != null) {
return;
@@ -141,7 +187,7 @@ namespace AstalSway {
public signal void container_float(Container con);
private async void handle_event(IpcReponse reply) {
- yield sync();
+ yield sync_tree();
switch (reply.type) {
case PayloadType.MESSAGE_SUBSCRIBE:
return;
@@ -154,6 +200,10 @@ namespace AstalSway {
handle_window_event(reply.payload);
break;
+ case PayloadType.EVENT_OUTPUT:
+ yield sync_outputs();
+ break;
+
default:
break;
}