mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-25 00:37:31 +02:00
Support rotated devices
This commit is contained in:
@ -252,6 +252,7 @@ _device_pattern = (
|
|||||||
+ "(?P<is_primary> primary)? ?"
|
+ "(?P<is_primary> primary)? ?"
|
||||||
+ "((?P<resolution_width>\d+)x(?P<resolution_height>\d+)"
|
+ "((?P<resolution_width>\d+)x(?P<resolution_height>\d+)"
|
||||||
+ "\+(?P<offset_width>\d+)\+(?P<offset_height>\d+))? "
|
+ "\+(?P<offset_width>\d+)\+(?P<offset_height>\d+))? "
|
||||||
|
+ "(?P<rotation>(inverted|left|right))? ?"
|
||||||
+ "\(normal left inverted right x axis y axis\)"
|
+ "\(normal left inverted right x axis y axis\)"
|
||||||
+ "( ((?P<dimension_width>\d+)mm x (?P<dimension_height>\d+)mm)?)?"
|
+ "( ((?P<dimension_width>\d+)mm x (?P<dimension_height>\d+)mm)?)?"
|
||||||
)
|
)
|
||||||
@ -275,9 +276,10 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device
|
|||||||
"is_primary": matches["is_primary"] is not None
|
"is_primary": matches["is_primary"] is not None
|
||||||
and len(matches["is_primary"]) > 0,
|
and len(matches["is_primary"]) > 0,
|
||||||
"device_name": matches["device_name"],
|
"device_name": matches["device_name"],
|
||||||
|
"rotation": matches["rotation"] or "normal",
|
||||||
}
|
}
|
||||||
for k, v in matches.items():
|
for k, v in matches.items():
|
||||||
if k not in {"is_connected", "is_primary", "device_name"}:
|
if k not in {"is_connected", "is_primary", "device_name", "rotation"}:
|
||||||
try:
|
try:
|
||||||
if v:
|
if v:
|
||||||
device[k] = int(v)
|
device[k] = int(v)
|
||||||
|
1
tests/fixtures/generic/xrandr_simple.json
vendored
1
tests/fixtures/generic/xrandr_simple.json
vendored
@ -43,6 +43,7 @@
|
|||||||
"is_connected": true,
|
"is_connected": true,
|
||||||
"is_primary": true,
|
"is_primary": true,
|
||||||
"device_name": "eDP1",
|
"device_name": "eDP1",
|
||||||
|
"rotation": "normal",
|
||||||
"resolution_width": 1920,
|
"resolution_width": 1920,
|
||||||
"resolution_height": 1080,
|
"resolution_height": 1080,
|
||||||
"offset_width": 0,
|
"offset_width": 0,
|
||||||
|
@ -30,7 +30,8 @@ class XrandrTests(unittest.TestCase):
|
|||||||
"HDMI1 connected (normal left inverted right x axis y axis)",
|
"HDMI1 connected (normal left inverted right x axis y axis)",
|
||||||
"VIRTUAL1 disconnected (normal left inverted right x axis y axis)",
|
"VIRTUAL1 disconnected (normal left inverted right x axis y axis)",
|
||||||
"eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 310mm x 170mm",
|
"eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 310mm x 170mm",
|
||||||
"eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 309mm x 174mm"
|
"eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 309mm x 174mm",
|
||||||
|
"HDMI-0 connected 2160x3840+3840+0 right (normal left inverted right x axis y axis) 609mm x 349mm",
|
||||||
]
|
]
|
||||||
for device in devices:
|
for device in devices:
|
||||||
self.assertIsNotNone(re.match(_device_pattern, device))
|
self.assertIsNotNone(re.match(_device_pattern, device))
|
||||||
@ -85,7 +86,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_device(self):
|
def test_device(self):
|
||||||
# regex101 sample link for tests/edits https://regex101.com/r/3cHMv3/1
|
# regex101 sample link for tests/edits https://regex101.com/r/3cHMv3/1
|
||||||
sample = "eDP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 310mm x 170mm"
|
sample = "eDP1 connected primary 1920x1080+0+0 left (normal left inverted right x axis y axis) 310mm x 170mm"
|
||||||
actual: Optional[Device] = _parse_device([sample])
|
actual: Optional[Device] = _parse_device([sample])
|
||||||
|
|
||||||
expected = {
|
expected = {
|
||||||
@ -98,6 +99,7 @@ class XrandrTests(unittest.TestCase):
|
|||||||
"offset_height": 0,
|
"offset_height": 0,
|
||||||
"dimension_width": 310,
|
"dimension_width": 310,
|
||||||
"dimension_height": 170,
|
"dimension_height": 170,
|
||||||
|
"rotation": "left",
|
||||||
}
|
}
|
||||||
|
|
||||||
self.assertIsNotNone(actual)
|
self.assertIsNotNone(actual)
|
||||||
@ -178,4 +180,4 @@ class XrandrTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user