Skip to content

New example #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4dab803
changed send_json and its dependent functions to be non-blocking.
Sep 5, 2024
af7cca1
connect client after timeout
Sep 5, 2024
d386fac
changed to the previous read_exact
Sep 5, 2024
0364132
read_exact using bytearray but returning bytes
Sep 5, 2024
9d43a66
don't reconnect client after response timeout
Sep 5, 2024
c55d4ac
handle exceptions in read_next_event
Sep 5, 2024
a3ad412
raise exception instead of print
Sep 5, 2024
a3cb282
Add function to check if the client is connected
Sep 7, 2024
50099a4
Remove unused var
Sep 7, 2024
7363f04
Removed client connection after exception
Sep 7, 2024
2a975f1
removed orjson
Sep 8, 2024
32db7b5
replaced is_socket_active with is_connected
Sep 8, 2024
5867101
make sure there is no way to hang while sending data.
Sep 9, 2024
07a2c97
remove send with timeout, causing issues with create_wayland_output
Sep 9, 2024
4d13912
add more seconds to create_wayland_output
Sep 9, 2024
58d97e4
allow the user decide the send_json timeout
Sep 9, 2024
905331d
removed timeout from create wayland output
Sep 9, 2024
4e15924
Merge branch 'WayfireWM:main' into main
killown Mar 25, 2025
81af49e
add cursor position getter returning (x,y)
Mar 25, 2025
20efe81
reset
Mar 25, 2025
39e0d8d
add cursor position getter returning (x,y)
Mar 25, 2025
4282cf0
docs(socket): fix missing reference in docstring
Mar 25, 2025
af47f1b
Merge branch 'WayfireWM:main' into main
killown Apr 15, 2025
def8835
new example: test ipc.
May 4, 2025
d764615
add more methods
May 5, 2025
8e4ed44
add clear bindings
May 5, 2025
66848f4
Adding new lines for better readability
May 5, 2025
97f072e
add more methods
May 6, 2025
80e2cba
add new ipc methods
Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions scripts/test_ipc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
from wayfire import WayfireSocket
import subprocess
import time
import sys

# === Configuration ===
TERMINAL = "kitty" # or "alacritty"
TITLE = "Simple Pywayfire Tests"

# Set up the socket and shell commands
sock = WayfireSocket()


def find_view_by_title(title: str):
views = sock.list_views()
for v in views:
if v.get("title") == title and v.get("role") == "toplevel" and v.get("mapped"):
return v
return None


def launch_terminal():
if TERMINAL == "kitty":
subprocess.Popen(
[
"kitty",
"--title",
TITLE,
"sh",
"-c",
"echo 'Wayfire test terminal'; sleep 1000",
]
)
elif TERMINAL == "alacritty":
subprocess.Popen(
[
"alacritty",
"--title",
TITLE,
"-e",
"sh",
"-c",
"echo 'Wayfire test terminal'; sleep 1000",
]
)
else:
raise ValueError(f"Unsupported terminal: {TERMINAL}")


def wait_for_view(title: str, timeout=10):
print(f"Waiting for view with title '{title}'...")
start = time.time()
while True:
view = find_view_by_title(title)
if view:
print(f"Found view: {view['id']} ({view['title']})")
return view
if time.time() - start > timeout:
raise TimeoutError(f"Timeout waiting for view with title '{title}'")
time.sleep(0.2)


def restore_state(view_id, original_alpha, original_sticky, original_fullscreen):
print("[RESTORE] Restoring original state...")
sock.set_view_alpha(view_id, original_alpha)
sock.set_view_sticky(view_id, original_sticky)
sock.set_view_fullscreen(view_id, original_fullscreen)
sock.set_view_always_on_top(view_id, False)
sock.set_view_minimized(view_id, False)
sock.set_option_values({"core/xwayland": True})
sock.send_view_to_back(view_id, False)

print("[RESTORE] Done.")


def main():
try:
# Launch terminal
print(f"Launching {TERMINAL} with title '{TITLE}'...")
launch_terminal()

view = wait_for_view(TITLE)
view_id = view["id"]

# Save original state
original_alpha = view.get("alpha", 1.0)
original_sticky = view.get("sticky", False)
original_fullscreen = view.get("fullscreen", False)

print(
f"Original Alpha: {original_alpha}, Sticky: {original_sticky}, Fullscreen: {original_fullscreen}"
)

print("Focusing view...")
sock.set_focus(view_id)

print("Resizing and moving view...")
sock.configure_view(view_id, 100, 100, 800, 600)

print("Setting transparency...")
sock.set_view_alpha(view_id, 0.7)

print("Toggling sticky state...")
sock.set_view_sticky(view_id, not original_sticky)

print("Toggling fullscreen...")
sock.set_view_fullscreen(view_id, not original_fullscreen)

print("Setting always-on-top...")
sock.set_view_always_on_top(view_id, True)

print("Setting config options")
sock.set_option_values({"core/xwayland": False})

print("Setting view workspace")
sock.set_workspace(0, 0, view_id)

print("Setting view minimized")
sock.set_view_minimized(view_id, True)

print("Sending view to back")
sock.send_view_to_back(view_id, True)

print("Sending view to wset")
wset_index = view["wset-index"]
sock.send_view_to_wset(view_id, wset_index)

print("Setting output wset")
output_id = view["output-id"]
sock.set_output_wset(output_id, wset_index)

print("Using get functions")
sock.get_focused_view()
sock.get_cursor_position()
focused_output_id = sock.get_focused_output()["id"]
sock.get_view(view_id)
sock.get_option_value("core/plugins")
sock.get_configuration()
sock.get_output(focused_output_id)
layout_index = sock.get_keyboard_layout()["layout-index"]

print("Setting keyboard layout")
sock.set_keyboard_layout(layout_index)

print("Using list functions")
sock.list_views()
sock.list_methods()
sock.list_input_devices()
sock.list_wsets()
sock.list_outputs()

print(f"Assign {TERMINAL} to the slots")
positions = ["tl", "tr", "bl", "br", "br", "t", "b", "l", "r", "c"]
for position in positions:
sock.assign_slot(view_id, f"slot_{position}")

print("Creating headless output")
headless_output_name = sock.create_headless_output(100, 100)["output"]["name"]

print("Destroying headless output")
sock.destroy_headless_output(headless_output_name)

def register_binding():
print("Registering binding")
return sock.register_binding(
binding="<ctrl><super><alt> KEY_T",
call_method="scale/toggle", # use sock.list_methods for more info
call_data={},
exec_always=True,
mode="normal",
)

sock.unregister_binding(register_binding()["binding-id"])
print("Unregistering binding")

print("Registering binding again to test clear_bindings")
register_binding()

print("Clearing bindings")
sock.clear_bindings()

# Restore original state
restore_state(view_id, original_alpha, original_sticky, original_fullscreen)

print(f"Closing {TERMINAL}")
sock.close_view(view_id)

print("Tests finished ✅")

except Exception as e:
print(f"[ERROR] {e}")
sys.exit(1)


if __name__ == "__main__":
main()