raster pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=1cfd1f4242eee71a327104c5e38fe64f6002a795

commit 1cfd1f4242eee71a327104c5e38fe64f6002a795
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Fri Feb 7 10:24:59 2020 +0000

    backlight - add workaround monitor wakeups silently ignoring val sets
    
    so if monitor is buys waking up from dpms, it may not be bothering to
    do what we asked... but the sets of the propety say they succeed, so
    use the get at the end of a fade in run to see if we get the target
    brightness within some delta and it's one of our standard brightnesses
    (1.0, normal or dim) and retry a few times until we succeed or give
    up. this ensures on wakupe your monitors end up at their target
    brightness even with some hiccups as opposed to stay dim. not much we
    can do about iffy hardware or libddcutil (not sure which is to blame)
    other than do workarounds like this.
    
    also add logging so you can see what is being asked and if it succeeds
    or fails according to libddcutil.
---
 src/bin/e_backlight.c         | 43 +++++++++++++++++++++++++++++++++++++++++--
 src/bin/system/e_system_ddc.c |  5 +++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/src/bin/e_backlight.c b/src/bin/e_backlight.c
index 5dd1daea5..ea9d95349 100644
--- a/src/bin/e_backlight.c
+++ b/src/bin/e_backlight.c
@@ -5,9 +5,11 @@ typedef struct
    const char *dev;
    const char *output;
    const char *edid;
-   double val;
+   double val, expected_val;
    double from_val, to_val;
    Ecore_Animator *anim;
+   Ecore_Timer *retry_timer;
+   int retries;
 } Backlight_Device;
 
 E_API int E_EVENT_BACKLIGHT_CHANGE = -1;
@@ -19,6 +21,38 @@ static Eina_List *_devices = NULL;
 static int        _devices_pending_ops = 0;
 static Eina_Bool  _devices_zones_update = EINA_FALSE;
 
+static void _backlight_devices_device_set(Backlight_Device *bd, double val);
+static void _backlight_devices_device_update(Backlight_Device *bd);
+
+static Eina_Bool
+_backlight_retry_timer_cb(void *data)
+{
+   Backlight_Device *bd = data;
+   bd->retry_timer = NULL;
+   _backlight_devices_device_set(bd, bd->expected_val);
+   _backlight_devices_device_update(bd);
+   return EINA_FALSE;
+}
+
+static void
+_backlight_mismatch_retry(Backlight_Device *bd)
+{
+   if (// if want 1.0 or normal or dim
+       ((fabs(bd->expected_val - 1.0) < DBL_EPSILON) ||
+        (fabs(bd->expected_val - e_config->backlight.normal) < DBL_EPSILON) ||
+        (fabs(bd->expected_val - e_config->backlight.dim) < DBL_EPSILON)) &&
+       // and the delta between expected and val >= 0.05
+       (fabs(bd->expected_val - bd->val) >= 0.05) &&
+       // and we retried < 20 times
+       (bd->retries < 20))
+     { // try again
+        bd->retries++;
+        if (bd->retry_timer) ecore_timer_del(bd->retry_timer);
+        ecore_timer_add(0.1, _backlight_retry_timer_cb, bd);
+     } // or give up
+   else bd->retries = 0;
+}
+
 static void
 _backlight_system_get_cb(void *data, const char *params)
 {
@@ -36,6 +70,7 @@ _backlight_system_get_cb(void *data, const char *params)
      {
         bd->val = fval;
         ecore_event_add(E_EVENT_BACKLIGHT_CHANGE, NULL, NULL, NULL);
+        _backlight_mismatch_retry(bd);
      }
 }
 
@@ -51,11 +86,13 @@ _backlight_system_ddc_get_cb(void *data, const char *params)
    if (sscanf(params, "%256s %i %i", edid, &id, &val) != 3) return;
    if (!!strncmp(bd->edid, edid, strlen(edid))) return;
    e_system_handler_del("ddc-val-get", _backlight_system_ddc_get_cb, bd);
+   if (val < 0) return; // get failed.... don't update
    fval = (double)val / 100.0;
    if (fabs(fval - bd->val) >= DBL_EPSILON)
      {
         bd->val = fval;
         ecore_event_add(E_EVENT_BACKLIGHT_CHANGE, NULL, NULL, NULL);
+        _backlight_mismatch_retry(bd);
      }
 }
 
@@ -73,6 +110,7 @@ _backlight_devices_clear(void)
         eina_stringshare_del(bd->output);
         eina_stringshare_del(bd->edid);
         if (bd->anim) ecore_animator_del(bd->anim);
+        if (bd->retry_timer) ecore_timer_del(bd->retry_timer);
         e_system_handler_del("bklight-val", _backlight_system_get_cb, bd);
         e_system_handler_del("ddc-val-get", _backlight_system_ddc_get_cb, bd);
         free(bd);
@@ -176,7 +214,7 @@ _backlight_devices_randr_output_get(Ecore_X_Window root, 
const char *output, con
 static void
 _backlight_devices_device_set(Backlight_Device *bd, double val)
 {
-   bd->val = val;
+   bd->val = bd->expected_val = val;
 #ifndef HAVE_WAYLAND_ONLY
    if (!strcmp(bd->dev, "randr"))
      {
@@ -629,6 +667,7 @@ e_backlight_level_set(E_Zone *zone, double val, double tim)
    if (zone->bl_mode == E_BACKLIGHT_MODE_NORMAL) tim = 0.5;
    else if (tim < 0.0) tim = e_config->backlight.transition;
 
+   E_FREE_FUNC(bd->retry_timer, ecore_timer_del);
    E_FREE_FUNC(bd->anim, ecore_animator_del);
    bd->anim = ecore_animator_timeline_add(tim, _bl_anim, bd);
    bd->from_val = bl_now;
diff --git a/src/bin/system/e_system_ddc.c b/src/bin/system/e_system_ddc.c
index dac507c89..8087019c4 100644
--- a/src/bin/system/e_system_ddc.c
+++ b/src/bin/system/e_system_ddc.c
@@ -387,6 +387,7 @@ _do_list(Ecore_Thread *th)
 static Eina_Bool
 _id_ok(int id)
 {
+   if ((id < 0) || (id > 0xff)) return EINA_FALSE; // limited range
    if (id == 0x10) return EINA_TRUE; // backlight allowed
    return EINA_FALSE;
 }
@@ -433,10 +434,12 @@ _do_val_set(Ecore_Thread *th, const char *edid, int id, 
int val)
    if (ddc_func.ddca_set_non_table_vcp_value
        (ddc_dh[screen], id, (val >> 8) & 0xff, val & 0xff) == 0)
      {
+        fprintf(stderr, "DDC: set ok %s 0x%02x %i\n", edid, id, val);
         snprintf(buf, sizeof(buf), "%s %i %i ok", edid, id, val);
      }
    else
      {
+        fprintf(stderr, "DDC: set fail %s 0x%02x %i\n", edid, id, val);
 err:
         snprintf(buf, sizeof(buf), "%s %i %i err", edid, id, val);
      }
@@ -471,10 +474,12 @@ _do_val_get(Ecore_Thread *th, const char *edid, int id)
        (ddc_dh[screen], id, &valrec) == 0)
      {
         val = valrec.sl | (valrec.sh << 8);
+        fprintf(stderr, "DDC: get ok %s 0x%02x = %i\n", edid, id, val);
         snprintf(buf, sizeof(buf), "%s %i %i", edid, id, val);
      }
    else
      {
+        fprintf(stderr, "DDC: get fail %s 0x%02x\n", edid, id);
 err:
         snprintf(buf, sizeof(buf), "%s %i -1", edid, id);
      }

-- 


Reply via email to