Skip to content

Commit

Permalink
Restore initialization-presets on ddcutil events.
Browse files Browse the repository at this point in the history
Trying to avoid lock conflicts.
  • Loading branch information
digitaltrails committed Sep 25, 2024
1 parent e141c4e commit e3174c4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions vdu_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7496,13 +7496,12 @@ def create_ddcutil(self):
def vdu_connectivity_changed_callback(edid_encoded: str, event_type: int, flags: int):
if event_type == DdcEventType.DPMS_AWAKE.value:
log_info(f"DPMS awake event {event_type=} {edid_encoded=:.30}")
if self.lux_auto_controller is not None and self.lux_auto_controller.is_auto_enabled():
self.lux_auto_controller.adjust_brightness_now() # don't wait for normal interval to finish
elif event_type == DdcEventType.DPMS_ASLEEP.value:
if event_type == DdcEventType.DPMS_ASLEEP.value:
log_info(f"DPMS asleep event {event_type=} {edid_encoded=:.30}")
return
else:
log_info(f"Connected VDUs changed {event_type=} {flags=} {edid_encoded:.30}...")
self.start_refresh()
self.start_refresh(ddcutil_event=True)

change_handler = vdu_connectivity_changed_callback
log_debug("Enabled callback for VDU-connectivity-change D-Bus signals")
Expand Down Expand Up @@ -7612,10 +7611,10 @@ def lux_check_action(self) -> bool:
return False
self.lux_auto_controller.adjust_brightness_now()

def start_refresh(self) -> None:
def start_refresh(self, ddcutil_event: bool = False) -> None:
if not is_running_in_gui_thread():
log_debug("Reinvoke start_refresh() in GUI thread.")
self.main_window.run_in_gui_thread(self.start_refresh)
self.main_window.run_in_gui_thread(self.start_refresh, ddcutil_event)
return

def update_from_vdu(worker: WorkerThread) -> None:
Expand All @@ -7626,9 +7625,13 @@ def update_from_vdu(worker: WorkerThread) -> None:
log_info("Refresh commences")
self.ddcutil.refresh_connection()
self.detected_vdu_list = self.ddcutil.detect_vdus()
if ddcutil_event:
self.restore_vdu_intialization_presets()
for control_panel in self.main_window.get_main_panel().vdu_control_panels.values():
if control_panel.controller.get_full_id() in self.detected_vdu_list:
control_panel.refresh_from_vdu()
if self.lux_auto_controller is not None and self.lux_auto_controller.is_auto_enabled():
self.lux_auto_controller.adjust_brightness_now() # don't wait for normal interval to finish
except (subprocess.SubprocessError, ValueError, re.error, OSError) as e:
if self.refresh_data_task.vdu_exception is None:
self.refresh_data_task.vdu_exception = VduException(vdu_description="unknown", operation="unknown",
Expand Down Expand Up @@ -7680,6 +7683,7 @@ def restore_preset(self, preset: Preset, finished_func: Callable[[PresetTransiti

log_debug("restore_preset: try to obtain application_configuration_lock", trace=False) if log_debug_enabled else None
with self.application_lock: # The lock prevents a transition firing when the GUI/app is reconfiguring
log_debug("restore_preset: holding application_configuration_lock", trace=False) if log_debug_enabled else None
self.transitioning_dummy_preset = None
if not immediately:
self.transitioning_dummy_preset = PresetTransitionDummy(preset)
Expand Down

0 comments on commit e3174c4

Please sign in to comment.