2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <window-extensions.h>
22 #include <dali/public-api/object/any.h>
23 #include <dali/public-api/common/vector-wrapper.h>
34 typedef std::vector< std::string > HintContainer;
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";
40 void Tokenize(const std::string& str, HintContainer& hints, const std::string& delimiters = ",")
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);
45 while (std::string::npos != pos || std::string::npos != lastPos)
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);
53 void GetAppliedHints( Dali::Window window, HintContainer& hints )
55 Dali::Any nativeWindow = window.GetNativeHandle();
56 if ( !nativeWindow.Empty() )
58 Ecore_X_Window ecoreWindow;
59 nativeWindow.Get( ecoreWindow );
61 unsigned char* data = NULL;
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 );
66 if ((res == 8) && (n > 0))
70 Tokenize(ss.str(), hints);
82 namespace WindowExtensions
85 void EnableEffect( Window window, bool enable )
87 Any nativeWindow = window.GetNativeHandle();
89 DALI_ASSERT_ALWAYS( !nativeWindow.Empty() && "Empty window!!!" );
92 GetAppliedHints( window, hints );
95 ss << hints.size() << ":" << HINT_EFFECT_NAME << (enable ? HINT_ENABLE_POSTFIX : HINT_DISABLE_POSTFIX);
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 );
105 bool IsEffectEnabled( Window window )
107 Any nativeWindow = window.GetNativeHandle();
109 DALI_ASSERT_ALWAYS( !nativeWindow.Empty() && "Empty window!!!" );
112 GetAppliedHints( window, hints );
114 HintContainer::iterator iter = std::find( hints.begin(), hints.end(), HINT_EFFECT_NAME );
116 return iter != hints.end();
119 } // namespace WindowExtensions