Skip to content

Commit

Permalink
ipc-scripts: fix ipc-rules-demo (#1964)
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 authored Oct 19, 2023
1 parent faa5ba9 commit 0f97986
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions ipc-scripts/ipc-rules-demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit 0f97986

Please sign in to comment.