Adds getter and setter to efl window brightness 43/148643/7
authorBartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Fri, 8 Sep 2017 07:33:30 +0000 (09:33 +0200)
committerSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Fri, 22 Sep 2017 06:43:03 +0000 (08:43 +0200)
This functions were added, because actually there isn't any
brightness control function for Native Window. New Wrt message
type is added also, so brightness setting and getting could be
added to Web API now.

Change-Id: Id2422a24dedffd7e75e18709d6cc7bab69da10a7
Signed-off-by: Bartlomiej Kunikowski <b.kunikowski@partner.samsung.com>
Signed-off-by: Szymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
runtime/browser/native_window.cc
runtime/browser/native_window.h
runtime/browser/web_application.cc

index 43f6bef4a5c5c29a8103c107397b8c07acf1ae47..e08964fdcd07fdbf5c3c3fc9f88b3b5f65868fb6 100755 (executable)
@@ -16,6 +16,7 @@
 
 #include "runtime/browser/native_window.h"
 
+#include <efl_util.h>
 #include <Ecore_Wayland.h>
 #include <EWebKit.h>
 #include <EWebKit_internal.h>
@@ -291,6 +292,17 @@ void NativeWindow::SetCurrentViewModeFullScreen(bool mode) {
   currentViewModeFullScreen_ = mode;
 }
 
+int NativeWindow::SetWindowBrightness(int brightness) {
+  if (brightness > 100)
+    brightness = 100;
+
+  return efl_util_set_window_brightness(window_, brightness);
+}
+
+int NativeWindow::GetWindowBrightness(int& brightness) {
+  return efl_util_get_window_brightness(window_, &brightness);
+}
+
 void NativeWindow::Show() {
   evas_object_show(window_);
 }
index a3053897548e1d20bf7dd848953952c39ac871dc..3cd094d2b31239be71fc7db2b95941412d754941 100755 (executable)
@@ -51,6 +51,8 @@ class NativeWindow {
   void SetRotationLock(ScreenOrientation orientation);
   void SetAutoRotation();
   void SetCurrentViewModeFullScreen(bool mode);
+  int SetWindowBrightness(int brightness);
+  int GetWindowBrightness(int& brightness);
   int AddRotationHandler(RotationHandler handler);
   void RemoveRotationHandler(int id);
   int rotation() const { return rotation_; }
index 390f990082447504f950c0fa2716ae796f9f3211..3ed29602bf26ccd745fc69da62bfff5404b1b7e7 100755 (executable)
 #include <Ecore.h>
 
 #include <algorithm>
+#include <cstdlib>
 #include <map>
 #include <memory>
 #include <fstream>
+#include <string>
 #include <sstream>
 #include <vector>
 
@@ -916,6 +918,31 @@ void WebApplication::OnReceivedWrtMessage(WebView* view,
       ewk_ipc_wrt_message_data_del(ans);
     } else if (TYPE_IS("tizen://hide_splash_screen")) {
       splash_screen_->HideSplashScreen(SplashScreen::HideReason::CUSTOM);
+    } else if (TYPE_IS("tizen://set_window_brightness")) {
+      // Brightness value parsing
+      long l_brightness = strtol(msg_value, nullptr, 10);
+      if (l_brightness == 0 && strncmp(msg_value, "0", 1)) {
+        LOGGER(ERROR) << "Received invalid brightness value: " << msg_value;
+        ewk_ipc_wrt_message_data_value_set(msg, "error");
+      }
+
+      int brightness = static_cast<int>(l_brightness);
+      if (!window_->SetWindowBrightness(brightness)) {
+        ewk_ipc_wrt_message_data_value_set(msg, "success");
+      } else {
+        ewk_ipc_wrt_message_data_value_set(msg, "error");
+      }
+    } else if (TYPE_IS("tizen://get_window_brightness")) {
+      int brightness;
+      int status = window_->GetWindowBrightness(brightness);
+      std::string answer = "{\"status\":\"";
+      if (status == 0) {
+        answer += "success\",\"result\":";
+        answer += std::to_string(brightness) + "}";
+      } else {
+        answer += "error\"}";
+      }
+      ewk_ipc_wrt_message_data_value_set(msg, answer.c_str());
     }
 
     eina_stringshare_del(msg_ref_id);