Skip to content

Commit

Permalink
parts/displays: puavodisplays.xrandr: parse primary field
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomasjjrasanen committed Feb 24, 2024
1 parent b52beec commit 15ecb53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions parts/displays/puavodisplays/xrandr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __repr__(self) -> str:
(
(
_TokenId.CONNECTOR,
r"^(?P<name>[^\s]+) (?P<state>connected|disconnected) .*$",
r"^(?P<name>[^\s]+) (?P<state>connected|disconnected) (?P<primary>primary|).*$",
),
(
_TokenId.EOF,
Expand Down Expand Up @@ -178,10 +178,15 @@ def __action_create_output(
*,
name: str,
state: str,
primary: str,
) -> None:
if name in self.__displays:
raise UnexpectedOutputError("display is a duplicate", name)
self.__displays[name] = self.__last_output = {"name": name, "state": state}
self.__displays[name] = self.__last_output = {
"name": name,
"state": state,
"is_primary": primary != "",
}

def __action_create_prop(
self,
Expand Down
7 changes: 7 additions & 0 deletions parts/displays/tests/test_xrandr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_prop_parser():

assert prop == {
"eDP-1": {
"is_primary": True,
"name": "eDP-1",
"state": "connected",
"current_mode": {
Expand Down Expand Up @@ -746,6 +747,7 @@ def test_prop_parser():
},
},
"DP-1": {
"is_primary": False,
"name": "DP-1",
"state": "disconnected",
"props": {
Expand Down Expand Up @@ -828,6 +830,7 @@ def test_prop_parser():
},
},
"HDMI-1": {
"is_primary": False,
"name": "HDMI-1",
"state": "disconnected",
"props": {
Expand Down Expand Up @@ -912,6 +915,7 @@ def test_prop_parser():
},
},
"DP-2": {
"is_primary": False,
"name": "DP-2",
"state": "disconnected",
"props": {
Expand Down Expand Up @@ -994,6 +998,7 @@ def test_prop_parser():
},
},
"HDMI-2": {
"is_primary": False,
"name": "HDMI-2",
"state": "disconnected",
"props": {
Expand Down Expand Up @@ -1078,6 +1083,7 @@ def test_prop_parser():
},
},
"DP-3": {
"is_primary": False,
"name": "DP-3",
"state": "disconnected",
"props": {
Expand Down Expand Up @@ -1160,6 +1166,7 @@ def test_prop_parser():
},
},
"HDMI-3": {
"is_primary": False,
"name": "HDMI-3",
"state": "disconnected",
"props": {
Expand Down

0 comments on commit 15ecb53

Please sign in to comment.