Skip to content

Commit

Permalink
add raw ipc data to classes
Browse files Browse the repository at this point in the history
  • Loading branch information
acrisci committed Mar 5, 2020
1 parent 881ddef commit 8947b9f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions i3ipc/aio/connection.py
Expand Up @@ -123,6 +123,9 @@ class Con(con.Con):
:vartype pid: int
:ivar gaps: (gaps only)
:vartype gaps: :class:`Gaps <i3ipc.Gaps>`
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

async def command(self, command: str) -> List[CommandReply]:
Expand Down
4 changes: 4 additions & 0 deletions i3ipc/con.py
Expand Up @@ -73,9 +73,13 @@ class Con:
:vartype pid: int
:ivar gaps: (gaps only)
:vartype gaps: :class:`Gaps <i3ipc.Gaps>`
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data, parent, conn):
self.ipc_data = data
self._conn = conn
self.parent = parent

Expand Down
29 changes: 29 additions & 0 deletions i3ipc/events.py
Expand Up @@ -62,9 +62,12 @@ class WorkspaceEvent(IpcBaseEvent):
:ivar old: When the change is "focus", an old (object) property will be
present with the previous workspace if it exists.
:vartype old: :class:`Con` or :class:`None`
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data, conn, _Con=con.Con):
self.ipc_data = data
self.change = data['change']
self.current = None
self.old = None
Expand All @@ -84,9 +87,12 @@ class OutputEvent(IpcBaseEvent):
:ivar change: The type of change (currently only "unspecified").
:vartype change: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
self.change = data['change']


Expand All @@ -100,9 +106,12 @@ class ModeEvent(IpcBaseEvent):
:ivar pango_markup: Whether pango markup should be used for displaying this
mode.
:vartype pango_markup: bool
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
self.change = data['change']
self.pango_markup = data.get('pango_markup', False)

Expand All @@ -117,9 +126,12 @@ class WindowEvent(IpcBaseEvent):
:ivar change: The type of change.
:vartype change: str
:ivar container: The window's parent container.
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data, conn, _Con=con.Con):
self.ipc_data = data
self.change = data['change']
self.container = _Con(data['container'], None, conn)

Expand Down Expand Up @@ -150,6 +162,8 @@ class BarconfigUpdateEvent(IpcBaseEvent, BarConfigReply):
:ivar colors: Contains key/value pairs of colors. Each value is a color
code in hex, formatted #rrggbb (like in HTML).
:vartype colors: dict
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
pass

Expand All @@ -172,9 +186,12 @@ class BindingInfo:
:ivar input_type: This will be "keyboard" or "mouse" depending on whether
or not this was a keyboard or a mouse binding.
:vartype input_type: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
self.command = data['command']
self.event_state_mask = data.get('event_state_mask', [])
self.input_code = data['input_code']
Expand All @@ -196,9 +213,12 @@ class BindingEvent(IpcBaseEvent):
:vartype change: str
:ivar binding: Contains details about the binding that was run.
:vartype binding: :class:`BindingInfo <i3ipc.BindingInfo>`
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
self.change = data['change']
self.binding = BindingInfo(data['binding'])

Expand All @@ -211,9 +231,12 @@ class ShutdownEvent(IpcBaseEvent):
:ivar change: The type of change.
:vartype change: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
self.change = data['change']


Expand All @@ -229,9 +252,12 @@ class TickEvent(IpcBaseEvent):
i3 (<=4.15).
:ivar payload: The payload that was sent with the tick.
:vartype payload: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
# i3 didn't include the 'first' field in 4.15. See i3/i3#3271.
self.first = data.get('first', None)
self.payload = data['payload']
Expand All @@ -244,8 +270,11 @@ class InputEvent(IpcBaseEvent):
:vartype change: str
:ivar input: Information about the input that changed.
:vartype input: :class:`InputReply <i3ipc.InputReply>`
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""

def __init__(self, data):
self.ipc_data = data
self.change = data['change']
self.input = InputReply(data['input'])
19 changes: 19 additions & 0 deletions i3ipc/replies.py
Expand Up @@ -3,6 +3,7 @@

class _BaseReply:
def __init__(self, data):
self.ipc_data = data
for member in self.__class__._members:
value = data.get(member[0], None)
if value is not None:
Expand All @@ -24,6 +25,8 @@ class CommandReply(_BaseReply):
:vartype success: bool
:ivar error: A human-readable error message.
:vartype error: str or :class:`None` if no error message was set.
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('success', bool),
Expand Down Expand Up @@ -55,6 +58,8 @@ class WorkspaceReply(_BaseReply):
:vartype rect: :class:`Rect`
:ivar output: The video output this workspace is on (LVDS1, VGA1, ...).
:vartype output: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('num', int),
Expand Down Expand Up @@ -84,6 +89,8 @@ class OutputReply(_BaseReply):
:ivar rect: The rectangle of this output (equals the rect of the output it
is on).
:vartype rect: :class:`Rect`
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('name', str),
Expand Down Expand Up @@ -131,6 +138,8 @@ class BarConfigReply(_BaseReply):
:ivar colors: Contains key/value pairs of colors. Each value is a color
code in hex, formatted #rrggbb (like in HTML).
:vartype colors: dict
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('id', str),
Expand Down Expand Up @@ -161,6 +170,8 @@ class VersionReply(_BaseReply):
:vartype human_readable: str
:ivar loaded_config_file_name: The current config path.
:vartype loaded_config_file_name: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('major', int),
Expand All @@ -179,6 +190,8 @@ class ConfigReply(_BaseReply):
:ivar config: A string containing the config file as loaded by i3 most
recently.
:vartype config: str
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('config', str),
Expand All @@ -192,6 +205,8 @@ class TickReply(_BaseReply):
:ivar success: Whether the tick succeeded.
:vartype success: bool
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('success', bool),
Expand Down Expand Up @@ -222,6 +237,8 @@ class InputReply(_BaseReply):
:vartype xkb_active_layout_index: int
:ivar libinput: (Only libinput devices) An object describing the current device settings.
:vartype libinput: dict
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [
('identifier', str),
Expand Down Expand Up @@ -251,6 +268,8 @@ class SeatReply(_BaseReply):
:vartype focus: int
:ivar devices: An array of input devices that are attached to the seat.
:vartype devices: list(:class:`InputReply`)
:ivar ipc_data: The raw data from the i3 ipc.
:vartype ipc_data: dict
"""
_members = [('name', str), ('capabilities', int), ('focus', int),
('devices', InputReply._parse_list)]

0 comments on commit 8947b9f

Please sign in to comment.