diff --git a/ipc-scripts/ipc-rules-demo.py b/ipc-scripts/ipc-rules-demo.py index 9deaaae41..7df36641a 100644 --- a/ipc-scripts/ipc-rules-demo.py +++ b/ipc-scripts/ipc-rules-demo.py @@ -13,16 +13,22 @@ from wayfire_socket import * addr = os.getenv('WAYFIRE_SOCKET') -sock = WayfireSocket(addr) -sock.watch() + +# Important: we connect to Wayfire's IPC two times. The one socket is used for reading events (view-mapped, view-focused, etc). +# The other is used for sending commands and querying Wayfire. +# We could use the same socket, but this would complicate reading responses, as events and query responses would be mixed with just one socket. +events_sock = WayfireSocket(addr) +commands_sock = WayfireSocket(addr) +events_sock.watch() while True: - msg = sock.read_message() + msg = events_sock.read_message() # The view-mapped event is emitted when a new window has been opened. if "event" in msg and msg["event"] == "view-mapped": view = msg["view"] if view["app-id"] == "gedit": - output_data = sock.query_output(view["output"]) + output_data = commands_sock.query_output(view["output"]) + print(output_data) workarea = output_data["workarea"] # We want gedit to take a certain position (200,200) and a quarter of the output @@ -31,7 +37,7 @@ w = workarea['width'] // 2 h = workarea['height'] // 2 - sock.configure_view(view["id"], x, y, w, h) + commands_sock.configure_view(view["id"], x, y, w, h) # sock.assign_slot(view["id"], "slot_br") - sock.set_always_on_top(view["id"], True) - sock.set_view_alpha(view["id"], 0.5) + commands_sock.set_always_on_top(view["id"], True) + commands_sock.set_view_alpha(view["id"], 0.5)