mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-23 00:29:59 +02:00
Support rotated devices
This commit is contained in:
@ -252,6 +252,7 @@ _device_pattern = (
|
||||
+ "(?P<is_primary> primary)? ?"
|
||||
+ "((?P<resolution_width>\d+)x(?P<resolution_height>\d+)"
|
||||
+ "\+(?P<offset_width>\d+)\+(?P<offset_height>\d+))? "
|
||||
+ "(?P<rotation>(inverted|left|right))? ?"
|
||||
+ "\(normal left inverted right x axis y axis\)"
|
||||
+ "( ((?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
|
||||
and len(matches["is_primary"]) > 0,
|
||||
"device_name": matches["device_name"],
|
||||
"rotation": matches["rotation"] or "normal",
|
||||
}
|
||||
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:
|
||||
if 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_primary": true,
|
||||
"device_name": "eDP1",
|
||||
"rotation": "normal",
|
||||
"resolution_width": 1920,
|
||||
"resolution_height": 1080,
|
||||
"offset_width": 0,
|
||||
|
@ -30,7 +30,8 @@ class XrandrTests(unittest.TestCase):
|
||||
"HDMI1 connected (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",
|
||||
"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:
|
||||
self.assertIsNotNone(re.match(_device_pattern, device))
|
||||
@ -85,7 +86,7 @@ class XrandrTests(unittest.TestCase):
|
||||
|
||||
def test_device(self):
|
||||
# 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])
|
||||
|
||||
expected = {
|
||||
@ -98,6 +99,7 @@ class XrandrTests(unittest.TestCase):
|
||||
"offset_height": 0,
|
||||
"dimension_width": 310,
|
||||
"dimension_height": 170,
|
||||
"rotation": "left",
|
||||
}
|
||||
|
||||
self.assertIsNotNone(actual)
|
||||
@ -178,4 +180,4 @@ class XrandrTests(unittest.TestCase):
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user