mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-12 19:24:20 +02:00
i3-companion: use new protocol format
It's simple enough and I don't want to spawn a polybar-msg. Maybe at a later point, we may be smarter. The problem with the old socket is that if you send messages fast enough on it, polybar may believe they are one message since it is not length-encoded on its side and it's a simple FIFO file (so no message boundaries). Dunno why I didn't get a problem until now.
This commit is contained in:
parent
c56649ca95
commit
9cc40b8755
1 changed files with 13 additions and 4 deletions
|
@ -17,6 +17,7 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
|
import struct
|
||||||
|
|
||||||
import i3ipc
|
import i3ipc
|
||||||
from i3ipc.aio import Connection
|
from i3ipc.aio import Connection
|
||||||
|
@ -263,14 +264,22 @@ def polybar(module):
|
||||||
out.write(content)
|
out.write(content)
|
||||||
|
|
||||||
# Send it to polybar
|
# Send it to polybar
|
||||||
for name in glob.glob("/tmp/polybar_mqueue.*"):
|
cmd = bytes(f"#{module}.send.{content}", "utf-8")
|
||||||
|
data = b"polyipc" + struct.pack("=BIB", 0, len(cmd), 2) + cmd
|
||||||
|
for name in glob.glob(f"{os.getenv('XDG_RUNTIME_DIR')}/polybar/*.sock"):
|
||||||
try:
|
try:
|
||||||
with open(os.open(name, os.O_WRONLY | os.O_NONBLOCK), "w") as out:
|
reader, writer = await asyncio.open_unix_connection(name)
|
||||||
cmd = f"action:#{module}.send.{content}"
|
|
||||||
out.write(cmd)
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENXIO:
|
if e.errno != errno.ENXIO:
|
||||||
raise
|
raise
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
writer.write(data)
|
||||||
|
await writer.drain()
|
||||||
|
await reader.read()
|
||||||
|
finally:
|
||||||
|
writer.close()
|
||||||
|
await writer.wait_closed()
|
||||||
|
|
||||||
logger.info(f"polybar/{module}: content updated")
|
logger.info(f"polybar/{module}: content updated")
|
||||||
cache[module] = content
|
cache[module] = content
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue