2 * Copyright (c) 2019 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 "ecore-wl-event-handler.h"
33 const int ECORE_WL_EVENT_COUNT = 4;
35 //const char* CLIPBOARD_ATOM = "CBHM_MSG";
36 //const char* CLIPBOARD_SET_OWNER_MESSAGE = "SET_OWNER";
40 struct EcoreWlEventHandler::Impl
42 Impl(EcoreWlEventHandler* eventHandler, Ecore_Wl2_Window* window)
43 : mEventHandler(eventHandler)
45 , mEcoreEventHandlers(ECORE_WL_EVENT_COUNT)
48 // Register Client message events - accessibility etc
49 mEcoreEventHandlers.push_back(ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, EcoreWlEventClientMessage, eventHandler));
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));
55 // Register Window visibility change events
56 mEcoreEventHandlers.push_back(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, EcoreWlEventWindowVisibilityChange, eventHandler));
62 for(std::vector<Ecore_Event_Handler*>::iterator iter = mEcoreEventHandlers.begin(), endIter = mEcoreEventHandlers.end(); iter != endIter; ++iter)
64 ecore_event_handler_del(*iter);
68 static Eina_Bool EcoreWlEventClientMessage(void* data, int type, void* event)
71 Ecore_X_Event_Client_Message* eventClientMessage = static_cast<Ecore_X_Event_Client_Message*>(event);
72 EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
74 if (eventClientMessage->win == eventHandler->mImpl->mWindow)
76 if (eventClientMessage->message_type == ecore_x_atom_get(CLIPBOARD_ATOM))
78 if (!strcmp(eventClientMessage->data.b, CLIPBOARD_SET_OWNER_MESSAGE))
80 // Claim the ownership of the SECONDARY selection
81 ecore_x_selection_secondary_set(eventClientMessage->win, "", 1);
83 // Show the clipboard window
84 Clipboard::Get().ShowClipboard();
90 return ECORE_CALLBACK_PASS_ON;
93 static Eina_Bool EcoreWlEventSelectionClear(void* data, int type, void* event)
96 Ecore_X_Event_Selection_Clear* eventSelectionClear = static_cast<Ecore_X_Event_Selection_Clear*>(event);
97 EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
99 if (eventSelectionClear->win == eventHandler->mImpl->mWindow)
101 if (eventSelectionClear->selection == ECORE_X_SELECTION_SECONDARY)
103 // Request to get the content from Ecore
104 ecore_x_selection_secondary_request(eventSelectionClear->win, ECORE_X_SELECTION_TARGET_TEXT);
109 return ECORE_CALLBACK_PASS_ON;
112 static Eina_Bool EcoreWlEventSelectionNotify(void* data, int type, void* event)
115 Ecore_X_Event_Selection_Notify* eventSelectionNotify = static_cast<Ecore_X_Event_Selection_Notify*>(event);
116 EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
118 if (eventSelectionNotify->win == eventHandler->mImpl->mWindow)
120 Ecore_X_Selection_Data* selectionData = static_cast<Ecore_X_Selection_Data*>(eventSelectionNotify->data);
121 if (selectionData->data)
123 if (eventSelectionNotify->selection == ECORE_X_SELECTION_SECONDARY)
125 std::string content(reinterpret_cast<char*>(selectionData->data), selectionData->length);
127 ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
128 clipboardEventNotifier.SetContent(content);
129 clipboardEventNotifier.EmitContentSelectedSignal();
131 // Claim the ownership of the SECONDARY selection
132 ecore_x_selection_secondary_set(eventSelectionNotify->win, "", 1);
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" );
143 return ECORE_CALLBACK_PASS_ON;
146 static Eina_Bool EcoreWlEventWindowVisibilityChange(void* data, int type, void* event)
148 Ecore_Wl2_Event_Window_Visibility_Change* eventWindowVisibilityChange = static_cast<Ecore_Wl2_Event_Window_Visibility_Change*>(event);
150 EcoreWlEventHandler* eventHandler = static_cast<EcoreWlEventHandler*>(data);
152 // 0 is visible and 1 is invisible
153 eventHandler->SendEcoreWlVisibility(!eventWindowVisibilityChange->fully_obscured);
155 return ECORE_CALLBACK_PASS_ON;
158 EcoreWlEventHandler* mEventHandler;
159 Ecore_Wl2_Window* mWindow;
160 std::vector<Ecore_Event_Handler*> mEcoreEventHandlers;
163 EcoreWlEventHandler::EcoreWlEventHandler(Ecore_Wl2_Window* window,
164 EvasPluginVisibilityInterface& evasPluginVisibilityInterface)
165 : mEvasPluginVisibilityInterface(evasPluginVisibilityInterface)
168 mImpl = new Impl(this, window);
171 EcoreWlEventHandler::~EcoreWlEventHandler()
177 void EcoreWlEventHandler::SendEcoreWlVisibility(bool visibility)
179 mEvasPluginVisibilityInterface.OnEcoreWlVisibility(visibility);
182 } // namespace Internal
184 } // namespace Extension