Skip to content

Commit ab0fe5e

Browse files
committed
Poll for mode change confirmation in set_mode()
1 parent 22882da commit ab0fe5e

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎openrgb/orgb.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
import struct
33
import platform
4+
import time
45
import warnings
56
from openrgb import utils
67
from typing import Union, Any, Optional
@@ -333,9 +334,17 @@ def set_mode(self, mode: Union[str, int, utils.ModeData], save: bool = False, fo
333334
len(data)
334335
)
335336
self.comms.send_data(data)
336-
self.update()
337-
# OpenRGB 1.0+ can answer update() before it has applied the new mode
338-
self.active_mode = mode.id
337+
# OpenRGB 1.0+ can answer update() before it has applied the new mode,
338+
# so poll until the server reports the requested mode
339+
for _ in range(5):
340+
self.update()
341+
if self.active_mode == mode.id:
342+
break
343+
time.sleep(0.05)
344+
else:
345+
# The mode change may have been rejected by the server; trust the
346+
# request so the client doesn't fall back to the previous mode
347+
self.active_mode = mode.id
339348

340349
def set_custom_mode(self):
341350
'''

0 commit comments

Comments
 (0)