@@ -179,7 +179,7 @@ def _unpack_header(data: bytes) -> Tuple[bytes, int, int]:
179179 return struct .unpack (_struct_header , data [:_struct_header_size ])
180180
181181
182- async def _find_socket_path () -> Optional [str ]:
182+ async def _find_socket_path (disp : Optional [ str ] = None ) -> Optional [str ]:
183183 socket_path = None
184184
185185 def exists (path ):
@@ -205,7 +205,7 @@ def exists(path):
205205
206206 # next try the root window property
207207 try :
208- d = display .Display ()
208+ d = display .Display (disp )
209209 atom = d .get_atom ('I3_SOCKET_PATH' )
210210 root = d .screen ().root
211211 prop = root .get_full_property (atom , X .AnyPropertyType )
@@ -269,17 +269,21 @@ class Connection:
269269 :param auto_reconnect: Whether to attempt to reconnect if the connection to
270270 the socket is broken when i3 restarts.
271271 :type auto_reconnect: bool
272+ :param display: A custom DISPLAY to determinate the socket_path.
273+ :type display: str
272274
273275 :raises Exception: If the connection to i3 cannot be established.
274276 """
275- def __init__ (self , socket_path : Optional [str ] = None , auto_reconnect : bool = False ):
277+ def __init__ (self , socket_path : Optional [str ] = None , auto_reconnect : bool = False , * ,
278+ display : Optional [str ] = None ):
276279 self ._socket_path = socket_path
277280 self ._auto_reconnect = auto_reconnect
278281 self ._pubsub = _AIOPubSub (self )
279282 self ._subscriptions = set ()
280283 self ._main_future = None
281284 self ._reconnect_future = None
282285 self ._synchronizer = None
286+ self ._display = display
283287
284288 def _sync (self ):
285289 if self ._synchronizer is None :
@@ -390,7 +394,7 @@ async def connect(self) -> 'Connection':
390394 logger .info ('using user provided socket path: {}' , self ._socket_path )
391395
392396 if not self ._socket_path :
393- self ._socket_path = await _find_socket_path ()
397+ self ._socket_path = await _find_socket_path (self . _display )
394398
395399 if not self .socket_path :
396400 raise Exception ('Failed to retrieve the i3 or sway IPC socket path' )
0 commit comments