From 7486b0c7cd83b922ccc30ed797598433f2b7733f Mon Sep 17 00:00:00 2001 From: Jake Ob Date: Tue, 7 Feb 2023 12:39:44 +0200 Subject: [PATCH] Move the reflect value in its own key (xrandr) Currently the reflect value of a device is included in the rotation key as a combination of both rotation and reflection (e.g. normal X axis). With this modification we move the reflection value to its own key in the JSON document like so: ```json { ... "rotation": "...", "reflection": "..., ... } ``` Fixes: issue #360 --- jc/parsers/xrandr.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index ba2606be..283cf19b 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -50,7 +50,8 @@ Schema: "offset_height": integer, "dimension_width": integer, "dimension_height": integer, - "rotation": string + "rotation": string, + "reflection": string } ], "unassociated_devices": [ @@ -127,7 +128,8 @@ Examples: "offset_height": 0, "dimension_width": 310, "dimension_height": 170, - "rotation": "normal" + "rotation": "normal", + "reflection": "normal" } } ], @@ -185,6 +187,8 @@ try: "dimension_width": int, "dimension_height": int, "associated_modes": List[Mode], + "rotation": str, + "reflection": str, }, ) Screen = TypedDict( @@ -252,7 +256,8 @@ _device_pattern = ( + r"(?P primary)? ?" + r"((?P\d+)x(?P\d+)" + r"\+(?P\d+)\+(?P\d+))? " - + r"(?P.*?)? ?" + + r"(?P(normal|right|left|inverted)?) ?" + + r"(?P(X axis|Y axis|X and Y axis)?) ?" + r"\(normal left inverted right x axis y axis\)" + r"( ((?P\d+)mm x (?P\d+)mm)?)?" ) @@ -277,9 +282,10 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device and len(matches["is_primary"]) > 0, "device_name": matches["device_name"], "rotation": matches["rotation"] or "normal", + "reflection": matches["reflection"] or "normal", } for k, v in matches.items(): - if k not in {"is_connected", "is_primary", "device_name", "rotation"}: + if k not in {"is_connected", "is_primary", "device_name", "rotation", "reflection"}: try: if v: device[k] = int(v)