diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index f9c0853e..3906f924 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -252,6 +252,7 @@ _device_pattern = ( + "(?P primary)? ?" + "((?P\d+)x(?P\d+)" + "\+(?P\d+)\+(?P\d+))? " + + "(?P(inverted|left|right))? ?" + "\(normal left inverted right x axis y axis\)" + "( ((?P\d+)mm x (?P\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) diff --git a/tests/fixtures/generic/xrandr_simple.json b/tests/fixtures/generic/xrandr_simple.json index a5aff206..e03e79c8 100644 --- a/tests/fixtures/generic/xrandr_simple.json +++ b/tests/fixtures/generic/xrandr_simple.json @@ -43,6 +43,7 @@ "is_connected": true, "is_primary": true, "device_name": "eDP1", + "rotation": "normal", "resolution_width": 1920, "resolution_height": 1080, "offset_width": 0, diff --git a/tests/test_xrandr.py b/tests/test_xrandr.py index 8323adb4..8fce69b7 100644 --- a/tests/test_xrandr.py +++ b/tests/test_xrandr.py @@ -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() \ No newline at end of file + unittest.main()