discomfitor pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=7f638d98bf89558f06156f5dbed6dc0e7cbc174f

commit 7f638d98bf89558f06156f5dbed6dc0e7cbc174f
Author: Mike Blumenkrantz <zm...@osg.samsung.com>
Date:   Mon Jul 27 15:46:57 2015 -0400

    add functioning wayland screensaver support
    
    block xscreensaver events, manage input<->activation eventing
    
    fix T2525
---
 src/bin/e_comp.c        |   5 +-
 src/bin/e_comp_canvas.c |   6 +++
 src/bin/e_comp_x.c      |  86 ++++++------------------------
 src/bin/e_screensaver.c | 137 ++++++++++++++++++++++++++++++++++++++++++------
 src/bin/e_screensaver.h |   3 ++
 5 files changed, 150 insertions(+), 87 deletions(-)

diff --git a/src/bin/e_comp.c b/src/bin/e_comp.c
index 4d5295f..ca0176f 100644
--- a/src/bin/e_comp.c
+++ b/src/bin/e_comp.c
@@ -1069,7 +1069,10 @@ e_comp_init(void)
    if (e_comp->comp_type == E_PIXMAP_TYPE_NONE) return EINA_FALSE;
 out:
    if (e_comp->comp_type == E_PIXMAP_TYPE_WL)
-     e_comp_canvas_fake_layers_init();
+     {
+        e_comp_canvas_fake_layers_init();
+        e_screensaver_update();
+     }
    e_comp->elm = elm_win_fake_add(e_comp->ee);
    elm_win_fullscreen_set(e_comp->elm, 1);
    evas_object_show(e_comp->elm);
diff --git a/src/bin/e_comp_canvas.c b/src/bin/e_comp_canvas.c
index 367e102..bf8cb64 100644
--- a/src/bin/e_comp_canvas.c
+++ b/src/bin/e_comp_canvas.c
@@ -65,6 +65,7 @@ _e_comp_canvas_cb_mouse_in(void *d EINA_UNUSED, Evas *e 
EINA_UNUSED, Evas_Object
 {
    E_Client *ec;
 
+   e_screensaver_notidle();
    if (e_client_action_get()) return;
    ec = e_client_focused_get();
    if (ec && (!ec->border_menu)) e_focus_event_mouse_out(ec);
@@ -73,6 +74,7 @@ _e_comp_canvas_cb_mouse_in(void *d EINA_UNUSED, Evas *e 
EINA_UNUSED, Evas_Object
 static void
 _e_comp_canvas_cb_mouse_down(void *d EINA_UNUSED, Evas *e EINA_UNUSED, 
Evas_Object *obj EINA_UNUSED, void *event_info)
 {
+   e_screensaver_notidle();
    if (e_client_action_get()) return;
    e_bindings_mouse_down_evas_event_handle(E_BINDING_CONTEXT_COMPOSITOR, 
E_OBJECT(e_comp), event_info);
 }
@@ -80,6 +82,7 @@ _e_comp_canvas_cb_mouse_down(void *d EINA_UNUSED, Evas *e 
EINA_UNUSED, Evas_Obje
 static void
 _e_comp_canvas_cb_mouse_up(void *d EINA_UNUSED, Evas *e EINA_UNUSED, 
Evas_Object *obj EINA_UNUSED, void *event_info)
 {
+   e_screensaver_notidle();
    if (e_client_action_get()) return;
    e_bindings_mouse_up_evas_event_handle(E_BINDING_CONTEXT_COMPOSITOR, 
E_OBJECT(e_comp), event_info);
 }
@@ -87,6 +90,7 @@ _e_comp_canvas_cb_mouse_up(void *d EINA_UNUSED, Evas *e 
EINA_UNUSED, Evas_Object
 static void
 _e_comp_canvas_cb_mouse_wheel(void *d EINA_UNUSED, Evas *e EINA_UNUSED, 
Evas_Object *obj EINA_UNUSED, void *event_info)
 {
+   e_screensaver_notidle();
    if (e_client_action_get()) return;
    e_bindings_wheel_evas_event_handle(E_BINDING_CONTEXT_COMPOSITOR, 
E_OBJECT(e_comp), event_info);
 }
@@ -94,6 +98,7 @@ _e_comp_canvas_cb_mouse_wheel(void *d EINA_UNUSED, Evas *e 
EINA_UNUSED, Evas_Obj
 static Eina_Bool
 _e_comp_cb_key_down(void *data EINA_UNUSED, int ev_type EINA_UNUSED, 
Ecore_Event_Key *ev)
 {
+   e_screensaver_notidle();
    if (e_menu_grab_window_get())
      {
 #ifdef HAVE_WAYLAND
@@ -123,6 +128,7 @@ _e_comp_cb_key_down(void *data EINA_UNUSED, int ev_type 
EINA_UNUSED, Ecore_Event
 static Eina_Bool
 _e_comp_cb_key_up(void *data EINA_UNUSED, int ev_type EINA_UNUSED, 
Ecore_Event_Key *ev)
 {
+   e_screensaver_notidle();
    if (e_menu_grab_window_get())
      {
 #ifdef HAVE_WAYLAND
diff --git a/src/bin/e_comp_x.c b/src/bin/e_comp_x.c
index 0b4dea3..598608d 100644
--- a/src/bin/e_comp_x.c
+++ b/src/bin/e_comp_x.c
@@ -60,9 +60,6 @@ static int _e_comp_x_mapping_change_disabled = 0;
 static Ecore_X_Randr_Screen_Size screen_size = { -1, -1 };
 static int screen_size_index = -1;
 
-static Ecore_Timer *screensaver_idle_timer = NULL;
-static Eina_Bool screensaver_dimmed = EINA_FALSE;
-
 static Ecore_X_Atom backlight_atom = 0;
 extern double e_bl_val;
 
@@ -4553,67 +4550,13 @@ _e_comp_x_cb_ping(void *data EINA_UNUSED, int ev_type 
EINA_UNUSED, Ecore_X_Event
    return ECORE_CALLBACK_PASS_ON;
 }
 
-static Eina_Bool
-_e_comp_x_screensaver_idle_timer_cb(void *d EINA_UNUSED)
-{
-   ecore_event_add(E_EVENT_SCREENSAVER_ON, NULL, NULL, NULL);
-   screensaver_idle_timer = NULL;
-   return EINA_FALSE;
-}
-
 static Ecore_Timer *screensaver_eval_timer = NULL;
 static Eina_Bool saver_on = EINA_FALSE;
 
 static Eina_Bool
 _e_comp_x_screensaver_eval_cb(void *d EINA_UNUSED)
 {
-   if (saver_on)
-     {
-        if (e_config->backlight.idle_dim)
-          {
-             double t = e_config->screensaver_timeout -
-               e_config->backlight.timer;
-
-             if (t < 1.0) t = 1.0;
-             E_FREE_FUNC(screensaver_idle_timer, ecore_timer_del);
-             if (e_config->screensaver_enable)
-               screensaver_idle_timer = ecore_timer_add
-                   (t, _e_comp_x_screensaver_idle_timer_cb, NULL);
-             if (e_backlight_mode_get(NULL) != E_BACKLIGHT_MODE_DIM)
-               {
-                  e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_DIM);
-                  screensaver_dimmed = EINA_TRUE;
-               }
-          }
-        else
-          {
-             if (!e_screensaver_on_get())
-               ecore_event_add(E_EVENT_SCREENSAVER_ON, NULL, NULL, NULL);
-          }
-     }
-   else
-     {
-        if (screensaver_idle_timer)
-          {
-             E_FREE_FUNC(screensaver_idle_timer, ecore_timer_del);
-             if (e_config->backlight.idle_dim)
-               {
-                  if (e_backlight_mode_get(NULL) != E_BACKLIGHT_MODE_NORMAL)
-                    e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_NORMAL);
-               }
-          }
-        else
-          {
-             if (screensaver_dimmed)
-               {
-                  if (e_backlight_mode_get(NULL) != E_BACKLIGHT_MODE_NORMAL)
-                    e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_NORMAL);
-                  screensaver_dimmed = EINA_FALSE;
-               }
-             if (e_screensaver_on_get())
-               ecore_event_add(E_EVENT_SCREENSAVER_OFF, NULL, NULL, NULL);
-          }
-     }
+   e_screensaver_eval(saver_on);
    screensaver_eval_timer = NULL;
    return EINA_FALSE;
 }
@@ -4624,14 +4567,14 @@ _e_comp_x_screensaver_notify_cb(void *data EINA_UNUSED, 
int type EINA_UNUSED, Ec
    if ((ev->on) && (!saver_on))
      {
         saver_on = EINA_TRUE;
-       E_FREE_FUNC(screensaver_eval_timer, ecore_timer_del);
-       screensaver_eval_timer = ecore_timer_add(0.3, 
_e_comp_x_screensaver_eval_cb, NULL);
+        E_FREE_FUNC(screensaver_eval_timer, ecore_timer_del);
+        screensaver_eval_timer = ecore_timer_add(0.3, 
_e_comp_x_screensaver_eval_cb, NULL);
      }
    else if ((!ev->on) && (saver_on))
      {
         saver_on = EINA_FALSE;
-       E_FREE_FUNC(screensaver_eval_timer, ecore_timer_del);
-       screensaver_eval_timer = ecore_timer_add(0.3, 
_e_comp_x_screensaver_eval_cb, NULL);
+        E_FREE_FUNC(screensaver_eval_timer, ecore_timer_del);
+        screensaver_eval_timer = ecore_timer_add(0.3, 
_e_comp_x_screensaver_eval_cb, NULL);
      }
    return ECORE_CALLBACK_PASS_ON;
 }
@@ -5298,8 +5241,6 @@ e_comp_x_init(void)
         return EINA_FALSE;
      }
 
-   ecore_x_screensaver_event_listen_set(1);
-
    clients_win_hash = eina_hash_int32_new(NULL);
    damages_hash = eina_hash_int32_new(NULL);
    alarm_hash = eina_hash_int32_new(NULL);
@@ -5359,7 +5300,6 @@ e_comp_x_init(void)
                          _e_comp_x_cb_frame_extents_request, NULL);
    E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_PING,
                          _e_comp_x_cb_ping, NULL);
-   E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_SCREENSAVER_NOTIFY, 
_e_comp_x_screensaver_notify_cb, NULL);
    E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_RANDR_OUTPUT_PROPERTY_NOTIFY, 
_e_comp_x_backlight_notify_cb, NULL);
    if (ecore_x_randr_version_get() >= RANDR_VERSION_1_3)
      backlight_atom = ecore_x_atom_get("Backlight");
@@ -5367,11 +5307,16 @@ e_comp_x_init(void)
    if (!backlight_atom)
      backlight_atom = ecore_x_atom_get("BACKLIGHT");
 
-   ecore_x_screensaver_custom_blanking_enable();
+   if (e_comp->comp_type != E_PIXMAP_TYPE_WL)
+     {
+        ecore_x_screensaver_event_listen_set(1);
+        E_LIST_HANDLER_APPEND(handlers, ECORE_X_EVENT_SCREENSAVER_NOTIFY, 
_e_comp_x_screensaver_notify_cb, NULL);
+        ecore_x_screensaver_custom_blanking_enable();
 
-   e_screensaver_attrs_set(ecore_x_screensaver_timeout_get(),
-                           ecore_x_screensaver_blank_get(),
-                           ecore_x_screensaver_expose_get());
+        e_screensaver_attrs_set(ecore_x_screensaver_timeout_get(),
+                                ecore_x_screensaver_blank_get(),
+                                ecore_x_screensaver_expose_get());
+     }
    ecore_x_passive_grab_replay_func_set(_e_comp_x_grab_replay, NULL);
 
    e_client_hook_add(E_CLIENT_HOOK_DESK_SET, _e_comp_x_hook_client_desk_set, 
NULL);
@@ -5417,7 +5362,8 @@ e_comp_x_shutdown(void)
    E_FREE_FUNC(alarm_hash, eina_hash_free);
    E_FREE_FUNC(frame_extents, eina_hash_free);
    e_xsettings_shutdown();
-   ecore_x_screensaver_custom_blanking_disable();
+   if (e_comp->comp_type == E_PIXMAP_TYPE_X)
+     ecore_x_screensaver_custom_blanking_disable();
    if (x_fatal) return;
    e_atoms_shutdown();
    e_randr2_shutdown();
diff --git a/src/bin/e_screensaver.c b/src/bin/e_screensaver.c
index 583187c..fa06c36 100644
--- a/src/bin/e_screensaver.c
+++ b/src/bin/e_screensaver.c
@@ -22,9 +22,26 @@ static int _e_screensaver_expose = 0;
 static Ecore_Timer *_e_screensaver_suspend_timer = NULL;
 static Eina_Bool _e_screensaver_on = EINA_FALSE;
 
+static Ecore_Timer *screensaver_idle_timer = NULL;
+static Eina_Bool screensaver_dimmed = EINA_FALSE;
+
+#ifdef HAVE_WAYLAND
+static Ecore_Timer *_e_screensaver_timer;
+#endif
+
 E_API int E_EVENT_SCREENSAVER_ON = -1;
 E_API int E_EVENT_SCREENSAVER_OFF = -1;
 
+#ifdef HAVE_WAYLAND
+static Eina_Bool
+_e_screensaver_idle_timeout_cb(void *d EINA_UNUSED)
+{
+   e_screensaver_eval(1);
+   _e_screensaver_timer = NULL;
+   return EINA_FALSE;
+}
+#endif
+
 E_API int
 e_screensaver_timeout_get(Eina_Bool use_idle)
 {
@@ -52,21 +69,22 @@ e_screensaver_timeout_get(Eina_Bool use_idle)
 E_API void
 e_screensaver_update(void)
 {
-#ifndef HAVE_WAYLAND_ONLY
-   int timeout = 0, interval = 0, blanking = 0, expose = 0;
+   int timeout;
    Eina_Bool changed = EINA_FALSE;
 
    timeout = e_screensaver_timeout_get(EINA_TRUE);
-
-   interval = e_config->screensaver_interval;
-   blanking = e_config->screensaver_blanking;
-   expose = e_config->screensaver_expose;
-
    if (_e_screensaver_timeout != timeout)
      {
         _e_screensaver_timeout = timeout;
         changed = EINA_TRUE;
      }
+#ifndef HAVE_WAYLAND_ONLY
+   int interval = 0, blanking = 0, expose = 0;
+
+   interval = e_config->screensaver_interval;
+   blanking = e_config->screensaver_blanking;
+   expose = e_config->screensaver_expose;
+
 //   if (_e_screensaver_interval != interval)
 //     {
 //        _e_screensaver_interval = interval;
@@ -83,12 +101,19 @@ e_screensaver_update(void)
         changed = EINA_TRUE;
      }
 
-   if (e_comp_util_has_x())
+   if (e_comp->comp_type != E_PIXMAP_TYPE_WL)
      {
         if (changed)
           ecore_x_screensaver_set(timeout, interval, blanking, expose);
      }
 #endif
+#ifdef HAVE_WAYLAND
+   if (changed && (e_comp->comp_type == E_PIXMAP_TYPE_WL))
+     {
+        E_FREE_FUNC(_e_screensaver_timer, ecore_timer_del);
+        _e_screensaver_timer = ecore_timer_add(timeout, 
_e_screensaver_idle_timeout_cb, NULL);
+     }
+#endif
 }
 
 E_API void
@@ -281,6 +306,9 @@ _e_screensaver_handler_screensaver_off_cb(void *data 
EINA_UNUSED, int type EINA_
      }
    else if (_e_screensaver_ask_presentation_count)
      _e_screensaver_ask_presentation_count = 0;
+#ifdef HAVE_WAYLAND
+   _e_screensaver_timer = ecore_timer_add(_e_screensaver_timeout, 
_e_screensaver_idle_timeout_cb, NULL);
+#endif
    return ECORE_CALLBACK_PASS_ON;
 }
 
@@ -305,6 +333,14 @@ _e_screensaver_handler_desk_show_cb(void *data 
EINA_UNUSED, int type EINA_UNUSED
    return ECORE_CALLBACK_PASS_ON;
 }
 
+static Eina_Bool
+_e_screensaver_idle_timer_cb(void *d EINA_UNUSED)
+{
+   ecore_event_add(E_EVENT_SCREENSAVER_ON, NULL, NULL, NULL);
+   screensaver_idle_timer = NULL;
+   return EINA_FALSE;
+}
+
 EINTERN void
 e_screensaver_preinit(void)
 {
@@ -439,24 +475,93 @@ e_screensaver_on_get(void)
 E_API void
 e_screensaver_activate(void)
 {
+   if (e_screensaver_on_get()) return;
+
+   E_FREE_FUNC(screensaver_idle_timer, ecore_timer_del);
 #ifndef HAVE_WAYLAND_ONLY
-   if (e_comp_util_has_x())
-     {
-        ecore_x_screensaver_activate();
-     }
-#else
+   if (e_comp->comp_type != E_PIXMAP_TYPE_WL)
+     ecore_x_screensaver_activate();
+#endif
+#ifdef HAVE_WAYLAND
+   if (e_comp->comp_type == E_PIXMAP_TYPE_WL)
+     e_screensaver_eval(1);
+   E_FREE_FUNC(_e_screensaver_timer, ecore_timer_del);
 #endif
 }
 
 E_API void
 e_screensaver_deactivate(void)
 {
+   if (!e_screensaver_on_get()) return;
+
+   E_FREE_FUNC(screensaver_idle_timer, ecore_timer_del);
 #ifndef HAVE_WAYLAND_ONLY
-   if (e_comp_util_has_x())
+   if (e_comp->comp_type != E_PIXMAP_TYPE_WL)
+     ecore_x_screensaver_reset();
+#endif
+#ifdef HAVE_WAYLAND
+   if (e_comp->comp_type == E_PIXMAP_TYPE_WL)
+     e_screensaver_eval(0);
+   E_FREE_FUNC(_e_screensaver_timer, ecore_timer_del);
+#endif
+}
+
+E_API void
+e_screensaver_eval(Eina_Bool saver_on)
+{
+   if (saver_on)
+     {
+        if (e_config->backlight.idle_dim)
+          {
+             double t = e_config->screensaver_timeout -
+               e_config->backlight.timer;
+
+             if (t < 1.0) t = 1.0;
+             E_FREE_FUNC(screensaver_idle_timer, ecore_timer_del);
+             if (e_config->screensaver_enable)
+               screensaver_idle_timer = ecore_timer_add
+                   (t, _e_screensaver_idle_timer_cb, NULL);
+             if (e_backlight_mode_get(NULL) != E_BACKLIGHT_MODE_DIM)
+               {
+                  e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_DIM);
+                  screensaver_dimmed = EINA_TRUE;
+               }
+          }
+        else
+          {
+             if (!e_screensaver_on_get())
+               ecore_event_add(E_EVENT_SCREENSAVER_ON, NULL, NULL, NULL);
+          }
+        return;
+     }
+   if (screensaver_idle_timer)
+     {
+        E_FREE_FUNC(screensaver_idle_timer, ecore_timer_del);
+        if (e_config->backlight.idle_dim)
+          {
+             if (e_backlight_mode_get(NULL) != E_BACKLIGHT_MODE_NORMAL)
+               e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_NORMAL);
+          }
+        return;
+     }
+   if (screensaver_dimmed)
      {
-        ecore_x_screensaver_reset();
+        if (e_backlight_mode_get(NULL) != E_BACKLIGHT_MODE_NORMAL)
+          e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_NORMAL);
+        screensaver_dimmed = EINA_FALSE;
      }
-#else
+   if (e_screensaver_on_get())
+     ecore_event_add(E_EVENT_SCREENSAVER_OFF, NULL, NULL, NULL);
+}
+
+E_API void
+e_screensaver_notidle(void)
+{
+#ifdef HAVE_WAYLAND
+   if (_e_screensaver_timer)
+     ecore_timer_reset(_e_screensaver_timer);
+   if (e_screensaver_on_get())
+     e_screensaver_eval(0);
 #endif
 }
 
diff --git a/src/bin/e_screensaver.h b/src/bin/e_screensaver.h
index 3ca5c9c..d1de350 100644
--- a/src/bin/e_screensaver.h
+++ b/src/bin/e_screensaver.h
@@ -16,6 +16,9 @@ E_API Eina_Bool e_screensaver_on_get(void);
 E_API void e_screensaver_activate(void);
 E_API void e_screensaver_deactivate(void);
 
+E_API void e_screensaver_eval(Eina_Bool saver_on);
+E_API void e_screensaver_notidle(void);
+
 E_API extern int E_EVENT_SCREENSAVER_ON;
 E_API extern int E_EVENT_SCREENSAVER_OFF;
 

-- 


Reply via email to