8f01016b0bc08ebbdb0531d886e9502de0a5f09d
[platform/core/uifw/dali-extension.git] / dali-extension / internal / evas-plugin / ecore-wl-event-handler.cpp
1 /*
2  * Copyright (c) 2019 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 "ecore-wl-event-handler.h"
20
21 namespace Dali
22 {
23
24 namespace Extension
25 {
26
27 namespace Internal
28 {
29
30 namespace
31 {
32
33 const int ECORE_WL_EVENT_COUNT = 4;
34
35 //const char* CLIPBOARD_ATOM = "CBHM_MSG";
36 //const char* CLIPBOARD_SET_OWNER_MESSAGE = "SET_OWNER";
37
38 }
39
40 struct EcoreWlEventHandler::Impl
41 {
42   Impl(EcoreWlEventHandler* eventHandler, Ecore_Wl2_Window* window)
43   : mEventHandler(eventHandler)
44   , mWindow(window)
45   , mEcoreEventHandlers(ECORE_WL_EVENT_COUNT)
46   {
47 #if 0
48     // Register Client message events - accessibility etc
49     mEcoreEventHandlers.push_back(ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE,  EcoreWlEventClientMessage, eventHandler));
50
51     // Register Selection events - clipboard selection, Drag & Drop selection etc
52     mEcoreEventHandlers.push_back(ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR, EcoreWlEventSelectionClear, eventHandler));
53     mEcoreEventHandlers.push_back(ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, EcoreWlEventSelectionNotify, eventHandler));
54 #endif
55     // Register Window visibility change events
56     mEcoreEventHandlers.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, EcoreWlEventWindowVisibilityChange, eventHandler));
57
58   }
59
60   ~Impl()
61   {
62     for(std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandlers.begin(), endIter = mEcoreEventHandlers.end(); iter != endIter; ++iter)
63     {
64       ecore_event_handler_del(*iter);
65     }
66   }
67
68   static Eina_Bool EcoreWlEventClientMessage(void* data, int type, void* event)
69   {
70 #if 0
71     Ecore_X_Event_Client_Message* eventClientMessage = static_cast<Ecore_X_Event_Client_Message*>(event);
72     EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
73
74     if (eventClientMessage->win == eventHandler->mImpl->mWindow)
75     {
76       if (eventClientMessage->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
77       {
78         if (!strcmp(eventClientMessage->data.b, CLIPBOARD_SET_OWNER_MESSAGE))
79         {
80           // Claim the ownership of the SECONDARY selection
81           ecore_x_selection_secondary_set(eventClientMessage->win, "", 1);
82
83           // Show the clipboard window
84           Clipboard::Get().ShowClipboard();
85         }
86       }
87     }
88 #endif
89
90     return ECORE_CALLBACK_PASS_ON;
91   }
92
93   static Eina_Bool EcoreWlEventSelectionClear(void* data, int type, void* event)
94   {
95 #if 0
96     Ecore_X_Event_Selection_Clear* eventSelectionClear = static_cast<Ecore_X_Event_Selection_Clear*>(event);
97     EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
98
99     if (eventSelectionClear->win == eventHandler->mImpl->mWindow)
100     {
101       if (eventSelectionClear->selection == ECORE_X_SELECTION_SECONDARY)
102       {
103         // Request to get the content from Ecore
104         ecore_x_selection_secondary_request(eventSelectionClear->win, ECORE_X_SELECTION_TARGET_TEXT);
105       }
106     }
107 #endif
108
109     return ECORE_CALLBACK_PASS_ON;
110   }
111
112   static Eina_Bool EcoreWlEventSelectionNotify(void* data, int type, void* event)
113   {
114 #if 0
115     Ecore_X_Event_Selection_Notify* eventSelectionNotify = static_cast<Ecore_X_Event_Selection_Notify*>(event);
116     EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
117
118     if (eventSelectionNotify->win == eventHandler->mImpl->mWindow)
119     {
120       Ecore_X_Selection_Data* selectionData = static_cast<Ecore_X_Selection_Data*>(eventSelectionNotify->data);
121       if (selectionData->data)
122       {
123         if (eventSelectionNotify->selection == ECORE_X_SELECTION_SECONDARY)
124         {
125           std::string content(reinterpret_cast<char*>(selectionData->data), selectionData->length);
126
127           ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
128           clipboardEventNotifier.SetContent(content);
129           clipboardEventNotifier.EmitContentSelectedSignal();
130
131           // Claim the ownership of the SECONDARY selection
132           ecore_x_selection_secondary_set(eventSelectionNotify->win, "", 1);
133
134           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "EcoreWlEventSelectionNotify: Content(%d):\n" , selectionData->length );
135           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
136           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "%s\n", selectionData->data );
137           DALI_LOG_INFO( gSelectionEventLogFilter, Debug::General, "======================================\n" );
138         }
139       }
140     }
141 #endif
142
143     return ECORE_CALLBACK_PASS_ON;
144   }
145
146   static Eina_Bool EcoreWlEventWindowVisibilityChange(void* data, int type, void* event)
147   {
148     Ecore_Wl2_Event_Window_Visibility_Change* eventWindowVisibilityChange = static_cast<Ecore_Wl2_Event_Window_Visibility_Change*>(event);
149
150     EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
151
152     // 0 is visible and 1 is invisible
153     eventHandler->SendEcoreWlVisibility(!eventWindowVisibilityChange->fully_obscured);
154
155     return ECORE_CALLBACK_PASS_ON;
156   }
157
158   EcoreWlEventHandler* mEventHandler;
159   Ecore_Wl2_Window* mWindow;
160   std::vector<Ecore_Event_Handler*> mEcoreEventHandlers;
161 };
162
163 EcoreWlEventHandler::EcoreWlEventHandler(Ecore_Wl2_Window* window,
164                                          EvasPluginVisibilityInterface& evasPluginVisibilityInterface)
165 : mEvasPluginVisibilityInterface(evasPluginVisibilityInterface)
166 , mImpl(NULL)
167 {
168   mImpl = new Impl(this, window);
169 }
170
171 EcoreWlEventHandler::~EcoreWlEventHandler()
172 {
173   delete mImpl;
174   mImpl = NULL;
175 }
176
177 void EcoreWlEventHandler::SendEcoreWlVisibility(bool visibility)
178 {
179   mEvasPluginVisibilityInterface.OnEcoreWlVisibility(visibility);
180 }
181
182 }  // namespace Internal
183
184 }  // namespace Extension
185
186 }  // namespace Dali