-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathdevice_layouts.py
More file actions
256 lines (239 loc) · 6.96 KB
/
Copy pathdevice_layouts.py
File metadata and controls
256 lines (239 loc) · 6.96 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
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
"""
Device-layout registry for Mouser's interactive mouse view.
The goal is to keep device-specific visual layout data out of QML so adding a
new Logitech family becomes a data change instead of a UI rewrite.
"""
from __future__ import annotations
from copy import deepcopy
from core.logi_device_catalog import LOGI_DEVICE_LAYOUTS
MX_MASTER_LAYOUT = {
"key": "mx_master",
"label": "MX Master family",
"image_asset": "mouse.png",
"image_width": 460,
"image_height": 360,
"interactive": True,
"manual_selectable": True,
"note": "",
"hotspots": [
{
"buttonKey": "middle",
"label": "Middle button",
"summaryType": "mapping",
"normX": 0.33,
"normY": 0.45,
"labelSide": "left",
"labelOffX": -80,
"labelOffY": -100,
},
{
"buttonKey": "gesture",
"label": "Gesture button",
"summaryType": "gesture",
"normX": 0.70,
"normY": 0.63,
"labelSide": "left",
"labelOffX": -200,
"labelOffY": 60,
},
{
"buttonKey": "xbutton2",
"label": "Forward button",
"summaryType": "mapping",
"normX": 0.60,
"normY": 0.48,
"labelSide": "left",
"labelOffX": -300,
"labelOffY": 0,
},
{
"buttonKey": "xbutton1",
"label": "Back button",
"summaryType": "mapping",
"normX": 0.65,
"normY": 0.40,
"labelSide": "right",
"labelOffX": 200,
"labelOffY": 50,
},
{
"buttonKey": "hscroll_left",
"label": "Horizontal scroll",
"summaryType": "hscroll",
"isHScroll": True,
"normX": 0.60,
"normY": 0.375,
"labelSide": "right",
"labelOffX": 200,
"labelOffY": -50,
},
{
"buttonKey": "mode_shift",
"label": "Mode shift button",
"summaryType": "mapping",
"normX": 0.43,
"normY": 0.25,
"labelSide": "right",
"labelOffX": 150,
"labelOffY": -80,
},
],
}
GENERIC_MOUSE_LAYOUT = {
"key": "generic_mouse",
"label": "Generic mouse",
"image_asset": "icons/mouse-simple.svg",
"image_width": 220,
"image_height": 220,
"interactive": False,
"manual_selectable": False,
"note": (
"This device is detected and the backend can still probe HID++ features, "
"but Mouser does not have a dedicated visual overlay for it yet."
),
"hotspots": [],
}
MX_ANYWHERE_LAYOUT = {
"key": "mx_anywhere",
"label": "MX Anywhere family",
"image_asset": "mouse_mx_anywhere_3s.png",
"image_width": 400,
"image_height": 320,
"interactive": True,
"manual_selectable": True,
"note": "",
"hotspots": [
{
"buttonKey": "middle",
"label": "Middle button",
"summaryType": "mapping",
"normX": 0.33,
"normY": 0.46,
"labelSide": "left",
"labelOffX": -200,
"labelOffY": -60,
},
{
"buttonKey": "gesture",
"label": "Gesture button",
"summaryType": "gesture",
"normX": 0.46,
"normY": 0.28,
"labelSide": "right",
"labelOffX": 150,
"labelOffY": -70,
},
{
"buttonKey": "xbutton2",
"label": "Forward button",
"summaryType": "mapping",
"normX": 0.69,
"normY": 0.53,
"labelSide": "right",
"labelOffX": 150,
"labelOffY": 30,
},
{
"buttonKey": "xbutton1",
"label": "Back button",
"summaryType": "mapping",
"normX": 0.75,
"normY": 0.45,
"labelSide": "right",
"labelOffX": 200,
"labelOffY": -45,
},
],
}
MX_VERTICAL_LAYOUT = {
"key": "mx_vertical",
"label": "MX Vertical family",
"image_asset": "mx_vertical.png",
"image_width": 380,
"image_height": 360,
"interactive": True,
"manual_selectable": True,
"note": "",
"hotspots": [
{
"buttonKey": "middle",
"label": "Middle button",
"summaryType": "mapping",
"normX": 0.22,
"normY": 0.38,
"labelSide": "left",
"labelOffX": -200,
"labelOffY": -30,
},
{
"buttonKey": "xbutton2",
"label": "Forward button",
"summaryType": "mapping",
"normX": 0.55,
"normY": 0.32,
"labelSide": "right",
"labelOffX": 160,
"labelOffY": 80,
},
{
"buttonKey": "xbutton1",
"label": "Back button",
"summaryType": "mapping",
"normX": 0.63,
"normY": 0.28,
"labelSide": "right",
"labelOffX": 200,
"labelOffY": 30,
},
{
"buttonKey": "dpi_switch",
"label": "DPI switch",
"summaryType": "mapping",
"normX": 0.61,
"normY": 0.12,
"labelSide": "right",
"labelOffX": 160,
"labelOffY": -30,
},
],
}
DEVICE_LAYOUTS = {
"mx_master": MX_MASTER_LAYOUT,
"mx_anywhere": MX_ANYWHERE_LAYOUT,
"mx_vertical": MX_VERTICAL_LAYOUT,
"generic_mouse": GENERIC_MOUSE_LAYOUT,
**LOGI_DEVICE_LAYOUTS,
}
# Maps a device-specific key like "mx_master_3s" to its family layout key.
# Entries here let per-device keys fall back to the family layout until a
# dedicated layout is added. Extend this dict as new devices are cataloged.
_FAMILY_FALLBACKS = {
"mx_master_4": "mx_master",
"mx_master_3s": "mx_master",
"mx_master_3": "mx_master",
"mx_master_2s": "mx_master",
"mx_anywhere_2s": "mx_anywhere",
"mx_anywhere_3s": "mx_anywhere",
"mx_anywhere_3": "mx_anywhere",
}
def get_device_layout(layout_key=None):
"""Return the layout dict for *layout_key* with a fallback chain.
1. Exact match in DEVICE_LAYOUTS (device-specific, e.g. "mx_master_4")
2. Family fallback via _FAMILY_FALLBACKS (e.g. "mx_master_4" -> "mx_master")
3. generic_mouse
"""
key = layout_key or ""
layout = DEVICE_LAYOUTS.get(key)
if layout is None:
family = _FAMILY_FALLBACKS.get(key, "")
layout = DEVICE_LAYOUTS.get(family, DEVICE_LAYOUTS["generic_mouse"])
return deepcopy(layout)
def get_manual_layout_choices():
choices = [{"key": "", "label": "Auto-detect"}]
for layout in DEVICE_LAYOUTS.values():
if layout.get("manual_selectable"):
choices.append({
"key": layout["key"],
"label": layout.get("label", layout["key"]),
})
return choices