File: replies.py

package info (click to toggle)
python-i3ipc 2.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 580 kB
  • sloc: python: 2,968; makefile: 222; sh: 4
file content (346 lines) | stat: -rw-r--r-- 11,490 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
from .model import Rect, OutputMode


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:
                setattr(self, member[0], member[1](value))
            else:
                setattr(self, member[0], None)

    @classmethod
    def _parse_list(cls, data):
        return [cls(d) for d in data]


class CommandReply(_BaseReply):
    """A reply to the ``RUN_COMMAND`` message.

    .. seealso:: https://i3wm.org/docs/ipc.html#_command_reply

    :ivar success: Whether the command succeeded.
    :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),
        ('error', str),
    ]


class WorkspaceReply(_BaseReply):
    """A reply to the ``GET_WORKSPACES`` message.

    .. seealso:: https://i3wm.org/docs/ipc.html#_workspaces_reply

    :ivar num: The logical number of the workspace. Corresponds to the command
        to switch to this workspace. For named workspaces, this will be -1.
    :vartype num: int
    :ivar name: The name of this workspace (by default num+1), as changed by
        the user.
    :vartype name: str
    :ivar visible: Whether this workspace is currently visible on an output
        (multiple workspaces can be visible at the same time).
    :vartype visible: bool
    :ivar focused: Whether this workspace currently has the focus (only one
        workspace can have the focus at the same time).
    :vartype focused: bool
    :ivar urgent: Whether a window on this workspace has the "urgent" flag set.
    :vartype urgent: bool
    :ivar rect: The rectangle of this workspace (equals the rect of the output
        it is on)
    :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),
        ('name', str),
        ('visible', bool),
        ('focused', bool),
        ('urgent', bool),
        ('rect', Rect),
        ('output', str),
    ]


class OutputReply(_BaseReply):
    """A reply to the ``GET_OUTPUTS`` message.

    .. seealso:: https://i3wm.org/docs/ipc.html#_outputs_reply

    :ivar name: The name of this output (as seen in xrandr(1)).
    :vartype name: str
    :ivar active: Whether this output is currently active (has a valid mode).
    :vartype active: bool
    :ivar primary: Whether this output is currently the primary output.
    :vartype primary: bool
    :ivar current_workspace: The name of the current workspace that is visible
        on this output. :class:`None` if the output is not active.
    :vartype current_workspace: str or :class:`None` if the output is not active.
    :ivar rect: The rectangle of this output (equals the rect of the output it
        is on).
    :vartype rect: :class:`Rect`
    :ivar make: (sway only)
    :vartype make: str
    :ivar model: (sway only)
    :vartype model: str
    :ivar serial: (sway only)
    :vartype serial: str
    :ivar scale: (sway only)
    :vartype scale: float
    :ivar transform: (sway only)
    :vartype transform: str
    :ivar max_render_time: (sway only)
    :vartype max_render_time: int
    :ivar focused: (sway only)
    :vartype focused: bool
    :ivar dpms: (sway only)
    :vartype dpms: bool
    :ivar subpixel_hinting: (sway only)
    :vartype subpixel_hinting: str
    :ivar modes: (sway only)
    :vartype modes: list(:class:`OutputMode`)
    :ivar current_mode: (sway only)
    :vartype current_mode: :class:`OutputMode`
    :ivar ipc_data: The raw data from the i3 ipc.
    :vartype ipc_data: dict
    """
    _members = [
        ('name', str),
        ('active', bool),
        ('primary', bool),
        ('current_workspace', str),
        ('rect', Rect),
        # Sway only output fields:
        ('make', str),
        ('model', str),
        ('serial', str),
        ('scale', float),
        ('transform', str),
        ('max_render_time', int),
        ('focused', bool),
        ('dpms', bool),
        ('subpixel_hinting', str),
        ('modes', OutputMode._parse_list),
        ('current_mode', OutputMode),
    ]


class BarConfigGaps:
    """(sway only) The useless gaps for the bar.

    :ivar left: The gap to the left.
    :vartype left: int
    :ivar right: The gap to the right.
    :vartype right: int
    :ivar top: The gap on the top.
    :vartype top: int
    :ivar bottom: The gap on the bottom.
    :vartype bottom: int
    """
    def __init__(self, data):
        self.left = data['left']
        self.right = data['right']
        self.top = data['top']
        self.bottom = data['bottom']


class BarConfigReply(_BaseReply):
    """A reply to the ``GET_BAR_CONFIG`` message with a specified bar id.

    .. seealso:: https://i3wm.org/docs/ipc.html#_bar_config_reply

    :ivar id: The ID for this bar.
    :vartype id: str
    :ivar mode: Either dock (the bar sets the dock window type) or hide (the
        bar does not show unless a specific key is pressed).
    :vartype mode: str
    :ivar position: Either bottom or top at the moment.
    :vartype position: str
    :ivar status_command: Command which will be run to generate a statusline.
    :vartype status_command: str
    :ivar font: The font to use for text on the bar.
    :vartype font: str
    :ivar workspace_buttons: Display workspace buttons or not.
    :vartype workspace_buttons: bool
    :ivar binding_mode_indicator: Display the mode indicator or not.
    :vartype binding_mode_indicator: bool
    :ivar verbose: Should the bar enable verbose output for debugging.
    :vartype verbose: bool
    :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 tray_padding:
    :vartype tray_padding: int
    :ivar hidden_state:
    :vartype hidden_state: str
    :ivar modifier:
    :vartype modifier: int
    :ivar workspace_min_width:
    :vartype workspace_min_width: int
    :ivar strip_workspace_numbers:
    :vartype strip_workspace_numbers: bool
    :ivar strip_workspace_name:
    :vartype strip_workspace_name: bool
    :ivar gaps: (sway only)
    :vartype gaps: :class:`BarConfigGaps`
    :ivar bar_height: (sway only)
    :vartype bar_height: int
    :ivar status_padding: (sway only)
    :vartype status_padding: int
    :ivar status_edge_padding: (sway only)
    :vartype status_edge_padding: int
    :ivar ipc_data: The raw data from the i3 ipc.
    :vartype ipc_data: dict
    """
    _members = [
        ('id', str),
        ('tray_padding', int),
        ('hidden_state', str),
        ('mode', str),
        ('modifier', int),
        ('position', str),
        ('status_command', str),
        ('font', str),
        ('workspace_buttons', bool),
        ('workspace_min_width', int),
        ('strip_workspace_numbers', bool),
        ('strip_workspace_name', bool),
        ('binding_mode_indicator', bool),
        ('verbose', bool),
        ('colors', dict),
        ('gaps', BarConfigGaps),
        ('bar_height', int),
        ('status_padding', int),
        ('status_edge_padding', int),
    ]


class VersionReply(_BaseReply):
    """A reply to the ``GET_VERSION`` message.

    .. seealso:: https://i3wm.org/docs/ipc.html#_version_reply

    :ivar major: The major version of i3.
    :vartype major: int
    :ivar minor: The minor version of i3.
    :vartype minor: int
    :ivar patch: The patch version of i3.
    :vartype patch: int
    :ivar human_readable: A human-readable version of i3 containing the precise
        git version, build date and branch name.
    :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),
        ('minor', int),
        ('patch', int),
        ('human_readable', str),
        ('loaded_config_file_name', str),
    ]


class ConfigReply(_BaseReply):
    """A reply to the ``GET_CONFIG`` message.

    .. seealso:: https://i3wm.org/docs/ipc.html#_config_reply

    :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),
    ]


class TickReply(_BaseReply):
    """A reply to the ``SEND_TICK`` message.

    .. seealso:: https://i3wm.org/docs/ipc.html#_tick_reply

    :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),
    ]


class InputReply(_BaseReply):
    """(sway only) A reply to ``GET_INPUTS`` message.

    .. seealso:: https://github.com/swaywm/sway/blob/master/sway/sway-ipc.7.scd

    :ivar identifier: The identifier for the input device.
    :vartype identifier: str
    :ivar name: The human readable name for the device
    :vartype name: str
    :ivar vendor: The vendor code for the input device
    :vartype vendor: int
    :ivar product: The product code for the input device
    :vartype product: int
    :ivar type: The device type. Currently this can be keyboard, pointer,
        touch, tablet_tool, tablet_pad, or switch
    :vartype type: str
    :ivar xkb_active_layout_name: (Only keyboards) The name of the active keyboard layout in use
    :vartype xkb_active_layout_name: str
    :ivar xkb_layout_names: (Only keyboards) A list a layout names configured for the keyboard
    :vartype xkb_layout_names: list(str)
    :ivar xkb_active_layout_index: (Only keyboards) The index of the active keyboard layout in use
    :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),
        ('name', str),
        ('vendor', int),
        ('product', int),
        ('type', str),
        ('xkb_active_layout_name', str),
        ('xkb_layout_names', list),
        ('xkb_active_layout_index', int),
        ('libinput', dict),
    ]


class SeatReply(_BaseReply):
    """(sway only) A reply to the ``GET_SEATS`` message.

    .. seealso:: https://github.com/swaywm/sway/blob/master/sway/sway-ipc.7.scd

    :ivar name: The unique name for the seat.
    :vartype name: str
    :ivar capabilities: The number of capabilities the seat has.
    :vartype capabilities: int
    :ivar focus: The id of the node currently focused by the seat or _0_ when
        the seat is not currently focused by a node (i.e. a surface layer or
        xwayland unmanaged has focus)
    :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)]