Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import socket
  2. import struct
  3. import time
  4. import threading
  5. import math
  6. import os
  7.  
  8. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  9. s.connect(os.environ['SWAYSOCK'])
  10.  
  11. def monitor():
  12. while True:
  13. hdr = s.recv(14)
  14. assert hdr[0:6] == b"i3-ipc"
  15. len, type = struct.unpack("@2I", hdr[6:])
  16. print(s.recv(len))
  17.  
  18. threading.Thread(target=monitor).start()
  19.  
  20. start = time.time()
  21. while True:
  22. theta = 2*math.pi*(time.time() - start)
  23. print(theta % (2*math.pi))
  24. x = round(500 + 300*math.cos(theta))
  25. y = round(500 + 300*math.sin(theta))
  26. msg = b"seat seat0 cursor set %d %d" % (x, y)
  27. hdr = b"i3-ipc" + struct.pack("@2I", len(msg), 0)
  28. s.send(hdr)
  29. s.send(msg)
  30. time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement