Skip to content

Commit cec29f9

Browse files
author
Tony Crisci
committed
breaking: redo reply structures
Use Rect for workspace and output rects. Use InputReply for seat input devices. Add docs.
1 parent 1def7b4 commit cec29f9

File tree

5 files changed

+256
-189
lines changed

5 files changed

+256
-189
lines changed

i3ipc/aio/connection.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ async def command(self, cmd: str) -> List[CommandReply]:
483483
data = await self._message(MessageType.COMMAND, cmd)
484484

485485
if data:
486-
return json.loads(data, object_hook=CommandReply)
486+
data = json.loads(data)
487+
return [CommandReply(d) for d in data]
487488
else:
488489
return []
489490

@@ -494,7 +495,8 @@ async def get_version(self) -> VersionReply:
494495
:rtype: :class:`i3ipc.VersionReply`
495496
"""
496497
data = await self._message(MessageType.GET_VERSION)
497-
return json.loads(data, object_hook=VersionReply)
498+
data = json.loads(data)
499+
return VersionReply(data)
498500

499501
async def get_bar_config_list(self) -> List[str]:
500502
"""Gets the names of all bar configurations.
@@ -523,7 +525,8 @@ async def get_bar_config(self, bar_id=None) -> Optional[BarConfigReply]:
523525
bar_id = bar_config_list[0]
524526

525527
data = await self._message(MessageType.GET_BAR_CONFIG, bar_id)
526-
return json.loads(data, object_hook=BarConfigReply)
528+
data = json.loads(data)
529+
return BarConfigReply(data)
527530

528531
async def get_outputs(self) -> List[OutputReply]:
529532
"""Gets the list of current outputs.
@@ -532,7 +535,8 @@ async def get_outputs(self) -> List[OutputReply]:
532535
:rtype: list(:class:`i3ipc.OutputReply`)
533536
"""
534537
data = await self._message(MessageType.GET_OUTPUTS)
535-
return json.loads(data, object_hook=OutputReply)
538+
data = json.loads(data)
539+
return [OutputReply(d) for d in data]
536540

537541
async def get_workspaces(self) -> List[WorkspaceReply]:
538542
"""Gets the list of current workspaces.
@@ -541,7 +545,8 @@ async def get_workspaces(self) -> List[WorkspaceReply]:
541545
:rtype: list(:class:`i3ipc.WorkspaceReply`)
542546
"""
543547
data = await self._message(MessageType.GET_WORKSPACES)
544-
return json.loads(data, object_hook=WorkspaceReply)
548+
data = json.loads(data)
549+
return [WorkspaceReply(d) for d in data]
545550

546551
async def get_tree(self) -> Con:
547552
"""Gets the root container of the i3 layout tree.
@@ -577,7 +582,8 @@ async def get_config(self) -> ConfigReply:
577582
:rtype: :class:`i3ipc.ConfigReply`
578583
"""
579584
data = await self._message(MessageType.GET_CONFIG)
580-
return json.loads(data, object_hook=ConfigReply)
585+
data = json.loads(data)
586+
return ConfigReply(data)
581587

582588
async def send_tick(self, payload: str = "") -> TickReply:
583589
"""Sends a tick with the specified payload.
@@ -586,7 +592,8 @@ async def send_tick(self, payload: str = "") -> TickReply:
586592
:rtype: :class:`i3ipc.TickReply`
587593
"""
588594
data = await self._message(MessageType.SEND_TICK, payload)
589-
return json.loads(data, object_hook=TickReply)
595+
data = json.loads(data)
596+
return TickReply(data)
590597

591598
async def get_inputs(self) -> InputReply:
592599
"""(sway only) Gets the inputs connected to the compositor.
@@ -595,7 +602,8 @@ async def get_inputs(self) -> InputReply:
595602
:rtype: :class:`i3ipc.InputReply`
596603
"""
597604
data = await self._message(MessageType.GET_INPUTS)
598-
return json.loads(data, object_hook=InputReply)
605+
data = json.loads(data)
606+
return [InputReply(d) for d in data]
599607

600608
async def get_seats(self) -> SeatReply:
601609
"""(sway only) Gets the seats configured on the compositor
@@ -604,7 +612,8 @@ async def get_seats(self) -> SeatReply:
604612
:rtype: :class:`i3ipc.SeatReply`
605613
"""
606614
data = await self._message(MessageType.GET_SEATS)
607-
return json.loads(data, object_hook=SeatReply)
615+
data = json.loads(data)
616+
return [SeatReply(d) for d in data]
608617

609618
def main_quit(self, _error=None):
610619
"""Quits the running main loop for this connection."""

i3ipc/connection.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ def command(self, payload):
185185
"""
186186
data = self._message(MessageType.COMMAND, payload)
187187
if data:
188-
return json.loads(data, object_hook=CommandReply)
188+
data = json.loads(data)
189+
return [CommandReply(d) for d in data]
189190
else:
190191
return []
191192

@@ -196,7 +197,8 @@ def get_version(self):
196197
:rtype: :class:`i3ipc.VersionReply`
197198
"""
198199
data = self._message(MessageType.GET_VERSION, '')
199-
return json.loads(data, object_hook=VersionReply)
200+
data = json.loads(data)
201+
return VersionReply(data)
200202

201203
def get_bar_config(self, bar_id=None):
202204
"""Gets the bar configuration specified by the id.
@@ -216,7 +218,8 @@ def get_bar_config(self, bar_id=None):
216218
bar_id = bar_config_list[0]
217219

218220
data = self._message(MessageType.GET_BAR_CONFIG, bar_id)
219-
return json.loads(data, object_hook=BarConfigReply)
221+
data = json.loads(data)
222+
return BarConfigReply(data)
220223

221224
def get_bar_config_list(self):
222225
"""Gets the names of all bar configurations.
@@ -234,7 +237,8 @@ def get_outputs(self):
234237
:rtype: list(:class:`i3ipc.OutputReply`)
235238
"""
236239
data = self._message(MessageType.GET_OUTPUTS, '')
237-
return json.loads(data, object_hook=OutputReply)
240+
data = json.loads(data)
241+
return [OutputReply(d) for d in data]
238242

239243
def get_inputs(self):
240244
"""(sway only) Gets the inputs connected to the compositor.
@@ -243,7 +247,8 @@ def get_inputs(self):
243247
:rtype: :class:`i3ipc.InputReply`
244248
"""
245249
data = self._message(MessageType.GET_INPUTS, '')
246-
return json.loads(data, object_hook=InputReply)
250+
data = json.loads(data)
251+
return [InputReply(d) for d in data]
247252

248253
def get_seats(self):
249254
"""(sway only) Gets the seats configured on the compositor
@@ -252,7 +257,8 @@ def get_seats(self):
252257
:rtype: :class:`i3ipc.SeatReply`
253258
"""
254259
data = self._message(MessageType.GET_SEATS, '')
255-
return json.loads(data, object_hook=SeatReply)
260+
data = json.loads(data)
261+
return [SeatReply(d) for d in data]
256262

257263
def get_workspaces(self):
258264
"""Gets the list of current workspaces.
@@ -261,7 +267,8 @@ def get_workspaces(self):
261267
:rtype: list(:class:`i3ipc.WorkspaceReply`)
262268
"""
263269
data = self._message(MessageType.GET_WORKSPACES, '')
264-
return json.loads(data, object_hook=WorkspaceReply)
270+
data = json.loads(data)
271+
return [WorkspaceReply(ws) for ws in data]
265272

266273
def get_tree(self):
267274
"""Gets the root container of the i3 layout tree.
@@ -297,7 +304,8 @@ def get_config(self):
297304
:rtype: :class:`i3ipc.ConfigReply`
298305
"""
299306
data = self._message(MessageType.GET_CONFIG, '')
300-
return json.loads(data, object_hook=ConfigReply)
307+
data = json.loads(data)
308+
return ConfigReply(data)
301309

302310
def send_tick(self, payload=""):
303311
"""Sends a tick with the specified payload.
@@ -306,7 +314,8 @@ def send_tick(self, payload=""):
306314
:rtype: :class:`i3ipc.TickReply`
307315
"""
308316
data = self._message(MessageType.SEND_TICK, payload)
309-
return json.loads(data, object_hook=TickReply)
317+
data = json.loads(data)
318+
return TickReply(data)
310319

311320
def _subscribe(self, events):
312321
events_obj = []
@@ -332,7 +341,8 @@ def _subscribe(self, events):
332341
data = self._ipc_send(self._sub_socket, MessageType.SUBSCRIBE, json.dumps(events_obj))
333342
finally:
334343
self._sub_lock.release()
335-
result = json.loads(data, object_hook=CommandReply)
344+
data = json.loads(data)
345+
result = CommandReply(data)
336346
self.subscriptions |= events
337347
return result
338348

0 commit comments

Comments
 (0)