Merge "Added handler for ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / window-extensions.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <window-extensions.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/any.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <string>
25 #include <sstream>
26 #include <Ecore.h>
27 #include <Ecore_X.h>
28
29 // INTERNAL INCLUDES
30 #include <window.h>
31
32 namespace
33 {
34 typedef std::vector< std::string > HintContainer;
35
36 const char* HINT_EFFECT_NAME = "wm.comp.win.effect.enable";
37 const char* HINT_ENABLE_POSTFIX = ":1";
38 const char* HINT_DISABLE_POSTFIX = ":0";
39
40 void Tokenize(const std::string& str, HintContainer& hints, const std::string& delimiters = ",")
41 {
42   std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
43   std::string::size_type pos = str.find_first_of(delimiters, lastPos);
44
45   while (std::string::npos != pos || std::string::npos != lastPos)
46   {
47     hints.push_back(str.substr(lastPos, pos - lastPos));
48     lastPos = str.find_first_not_of(delimiters, pos);
49     pos = str.find_first_of(delimiters, lastPos);
50   }
51 }
52
53 void GetAppliedHints( Dali::Window window, HintContainer& hints )
54 {
55   Dali::Any nativeWindow = window.GetNativeHandle();
56   if ( !nativeWindow.Empty() )
57   {
58     Ecore_X_Window ecoreWindow;
59     nativeWindow.Get( ecoreWindow );
60
61     unsigned char* data = NULL;
62     int n = 0;
63     int res = ecore_x_window_prop_property_get( ecoreWindow, ECORE_X_ATOM_E_WINDOW_AUX_HINT_SUPPORTED_LIST,
64                                                 ECORE_X_ATOM_STRING, 0, &data, &n );
65
66     if ((res == 8) && (n > 0))
67     {
68       std::stringstream ss;
69       ss << data;
70       Tokenize(ss.str(), hints);
71     }
72
73     free(data);
74   }
75 }
76
77 }
78
79 namespace Dali
80 {
81
82 namespace WindowExtensions
83 {
84
85 void EnableEffect( Window window, bool enable )
86 {
87   Any nativeWindow = window.GetNativeHandle();
88
89   DALI_ASSERT_ALWAYS( !nativeWindow.Empty() && "Empty window!!!" );
90
91   HintContainer hints;
92   GetAppliedHints( window, hints );
93
94   std::stringstream ss;
95   ss << hints.size() << ":" << HINT_EFFECT_NAME << (enable ? HINT_ENABLE_POSTFIX : HINT_DISABLE_POSTFIX);
96
97   // Applied the window effect to the current window.
98   Ecore_X_Window ecoreWindow;
99   nativeWindow.Get(ecoreWindow);
100   ecore_x_window_prop_property_set( ecoreWindow, ECORE_X_ATOM_E_WINDOW_AUX_HINT,
101                                     ECORE_X_ATOM_STRING, 8,
102                                     ss.str().c_str(), ss.str().size() + 1 );
103 }
104
105 bool IsEffectEnabled( Window window )
106 {
107   Any nativeWindow = window.GetNativeHandle();
108
109   DALI_ASSERT_ALWAYS( !nativeWindow.Empty() && "Empty window!!!" );
110
111   HintContainer hints;
112   GetAppliedHints( window, hints );
113
114   HintContainer::iterator iter = std::find( hints.begin(), hints.end(), HINT_EFFECT_NAME );
115
116   return iter != hints.end();
117 }
118
119 } // namespace WindowExtensions
120
121 } // namespace Dali
122
123