Skip to content

Commit b5b06a9

Browse files
committed
fix powerbutton bug in holding code
1 parent 2d2f855 commit b5b06a9

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

src/hhd/plugins/powerbutton/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def autodetect(existing: Sequence[HHDPlugin]) -> Sequence[HHDPlugin]:
4949
if len(existing):
5050
return existing
5151

52-
from .base import get_config, DEFAULT_DEVICE
52+
from .const import get_config, get_default_config
5353

5454
cfg = get_config()
5555
if not cfg:
56-
return [PowerbuttondPlugin(DEFAULT_DEVICE)]
56+
return [PowerbuttondPlugin(get_default_config())]
5757

5858
return [PowerbuttondPlugin(cfg)]

src/hhd/plugins/powerbutton/base.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from hhd.utils import Context, expanduser
1313

14-
from .const import DEFAULT_DEVICE, SUPPORTED_DEVICES, PowerButtonConfig
14+
from .const import PowerButtonConfig
1515

1616
logger = logging.getLogger(__name__)
1717

@@ -109,17 +109,6 @@ def register_hold_button(b: PowerButtonConfig) -> evdev.InputDevice | None:
109109
return None
110110

111111

112-
def get_config() -> PowerButtonConfig | None:
113-
with open("/sys/devices/virtual/dmi/id/product_name") as f:
114-
prod = f.read().strip()
115-
116-
for d in SUPPORTED_DEVICES:
117-
if d.prod_name == prod:
118-
return d
119-
120-
return None
121-
122-
123112
def run_steam_shortpress(perms: Context):
124113
return run_steam_command("steam://shortpowerpress", perms)
125114

@@ -232,6 +221,8 @@ def power_button_timer(cfg: PowerButtonConfig, perms: Context, should_exit: Even
232221
dev = None
233222
logger.info(f"Waiting for steam to launch.")
234223
while not is_steam_gamescope_running(perms):
224+
if should_exit.is_set():
225+
return
235226
sleep(STEAM_WAIT_DELAY)
236227

237228
if not dev:

src/hhd/plugins/powerbutton/const.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,21 @@ class PowerButtonConfig(NamedTuple):
6464
),
6565
]
6666

67-
DEFAULT_DEVICE: PowerButtonConfig = PBC("uknown", "NA", "hold_emitted")
67+
68+
def get_config() -> PowerButtonConfig | None:
69+
with open("/sys/devices/virtual/dmi/id/product_name") as f:
70+
prod = f.read().strip()
71+
72+
for d in SUPPORTED_DEVICES:
73+
if d.prod_name == prod:
74+
return d
75+
76+
return None
77+
78+
79+
def get_default_config():
80+
# Prepare for per-manufacturer customization
81+
return PBC("uknown", "NA", "hold_emitted")
6882

6983

7084
# Legion go

0 commit comments

Comments
 (0)