feat: use fenster ipc (sway/i3 compatible)

This commit is contained in:
2026-02-27 21:03:11 +01:00
parent 7962947f80
commit f1c45a7f8c
7 changed files with 344 additions and 48 deletions

29
bar/services/fenster.py Normal file
View File

@@ -0,0 +1,29 @@
"""
Fenster/Sway IPC connection helper.
Provides a singleton I3 connection configured for Fenster's SWAYSOCK.
"""
import os
from fabric.i3 import I3
_connection: I3 | None = None
def get_i3_connection() -> I3:
"""Get the singleton I3 connection, configured for Fenster."""
global _connection
if _connection is None:
swaysock = os.environ.get("SWAYSOCK")
if swaysock:
I3.SOCKET_PATH = swaysock
elif not I3.SOCKET_PATH:
runtime_dir = os.environ.get(
"XDG_RUNTIME_DIR", f"/run/user/{os.getuid()}"
)
fallback = os.path.join(runtime_dir, "fenster.sock")
if os.path.exists(fallback):
I3.SOCKET_PATH = fallback
_connection = I3()
return _connection