diff --git a/i3ipc/connection.py b/i3ipc/connection.py index 4fffba0..6dcea84 100644 --- a/i3ipc/connection.py +++ b/i3ipc/connection.py @@ -15,6 +15,8 @@ import subprocess from threading import Timer, Lock import time +import Xlib +import Xlib.display python2 = sys.version_info[0] < 3 @@ -49,17 +51,10 @@ def __init__(self, socket_path=None, auto_reconnect=False): if not socket_path: try: - socket_path = subprocess.check_output(['i3', '--get-socketpath'], - close_fds=True, - universal_newlines=True).strip() - except Exception: - pass - - if not socket_path: - try: - socket_path = subprocess.check_output(['sway', '--get-socketpath'], - close_fds=True, - universal_newlines=True).strip() + disp = Xlib.display.Display() + root = disp.screen().root + i3atom = disp.intern_atom("I3_SOCKET_PATH") + socket_path = root.get_full_property(i3atom, Xlib.X.AnyPropertyType).value.decode() except Exception: pass