-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathtypes.py
More file actions
79 lines (67 loc) · 2.13 KB
/
types.py
File metadata and controls
79 lines (67 loc) · 2.13 KB
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
from enum import Enum
class MessageType(Enum):
COMMAND = 0
GET_WORKSPACES = 1
SUBSCRIBE = 2
GET_OUTPUTS = 3
GET_TREE = 4
GET_MARKS = 5
GET_BAR_CONFIG = 6
GET_VERSION = 7
GET_BINDING_MODES = 8
GET_CONFIG = 9
SEND_TICK = 10
# sway-specific command types
GET_INPUTS = 100
GET_SEATS = 101
class ReplyType(Enum):
COMMAND = 0
WORKSPACES = 1
SUBSCRIBE = 2
OUTPUTS = 3
TREE = 4
MARKS = 5
BAR_CONFIG = 6
VERSION = 7
BINDING_MODES = 8
GET_CONFIG = 9
TICK = 10
class EventType(Enum):
WORKSPACE = (1 << 0)
OUTPUT = (1 << 1)
MODE = (1 << 2)
WINDOW = (1 << 3)
BARCONFIG_UPDATE = (1 << 4)
BINDING = (1 << 5)
SHUTDOWN = (1 << 6)
TICK = (1 << 7)
INPUT = (1 << 21)
def to_string(self) -> str:
return str.lower(self.name)
@staticmethod
def from_string(val) -> 'EventType':
match = [e for e in EventType if e.to_string() == val]
if not match:
raise ValueError('event not implemented: ' + val)
return match[0]
def to_list(self) -> list[str]:
events_list = []
if self.value & EventType.WORKSPACE.value:
events_list.append(EventType.WORKSPACE.to_string())
if self.value & EventType.OUTPUT.value:
events_list.append(EventType.OUTPUT.to_string())
if self.value & EventType.MODE.value:
events_list.append(EventType.MODE.to_string())
if self.value & EventType.WINDOW.value:
events_list.append(EventType.WINDOW.to_string())
if self.value & EventType.BARCONFIG_UPDATE.value:
events_list.append(EventType.BARCONFIG_UPDATE.to_string())
if self.value & EventType.BINDING.value:
events_list.append(EventType.BINDING.to_string())
if self.value & EventType.SHUTDOWN.value:
events_list.append(EventType.SHUTDOWN.to_string())
if self.value & EventType.TICK.value:
events_list.append(EventType.TICK.to_string())
if self.value & EventType.INPUT.value:
events_list.append(EventType.INPUT.to_string())
return events_list