Revert "Fix clipboard paste issue" 13/293413/1
authorBowon Ryu <bowon.ryu@samsung.com>
Fri, 26 May 2023 07:30:16 +0000 (16:30 +0900)
committerBowon Ryu <bowon.ryu@samsung.com>
Fri, 26 May 2023 07:30:44 +0000 (16:30 +0900)
This reverts commit ba40b0179fab4526582a1b0abff86322cfa045af.

Change-Id: I6ed0e8f9d32a1f2eeb11bf01fc29d7be962459d2

dali/internal/clipboard/common/clipboard-impl.h
dali/internal/clipboard/generic/clipboard-impl-generic.cpp
dali/internal/clipboard/tizen-wayland/clipboard-impl-ecore-wl.cpp
dali/internal/clipboard/ubuntu-x11/clipboard-impl-x.cpp
dali/internal/window-system/common/event-handler.cpp
dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.cpp

index eeaae38..ec10c59 100644 (file)
@@ -92,20 +92,13 @@ public:
   bool IsVisible() const;
 
   /**
-  * @brief sending buffered data
+  * @brief exchange either sending or receiving buffered data
   *
+  * @param[in] type true for send buffered data, false for receive data to buffer
   * @param[in] event information pointer
+  * @return The buffer pointer for send or receive data
   */
-  void ExcuteSend(void* event);
-
-  /**
-  * @brief receiving buffered data
-  *
-  * @param[in] event information pointer
-  * @param[out] data The buffer pointer for receive data
-  * @param[out] length The buffer length for receive data
-  */
-  void ExcuteReceive(void* event, char*& data, int& length);
+  char* ExcuteBuffered(bool type, void* event);
 
 private:
   // Undefined
index 74b911e..43713af 100644 (file)
@@ -106,12 +106,9 @@ bool Clipboard::IsVisible() const
   return false;
 }
 
-void Clipboard::ExcuteSend(void* event)
-{
-}
-
-void Clipboard::ExcuteReceive(void* event, char*& data, int& length)
+char* Clipboard::ExcuteBuffered(bool type, void* event)
 {
+  return NULL;
 }
 
 } // namespace Adaptor
index c3dc462..1cd452b 100644 (file)
@@ -117,48 +117,50 @@ struct Clipboard::Impl
     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
     mSerial                = ecore_wl2_dnd_selection_set(input, types);
 #else
-    mSerial                = ecore_wl_dnd_selection_set(ecore_wl_input_get(), types);
+    mSerial               = ecore_wl_dnd_selection_set(ecore_wl_input_get(), types);
 #endif
   }
 
   void RequestItem()
   {
+#ifdef ECORE_WAYLAND2
+    Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
+    ecore_wl2_dnd_selection_get(input);
+#else
     const char* types[10] = {
       0,
     };
     int i = -1;
 
     types[++i] = "text/plain;charset=utf-8";
-
-#ifdef ECORE_WAYLAND2
-    Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
-    Ecore_Wl2_Input*   input   = ecore_wl2_input_default_input_get(display);
-    Ecore_Wl2_Offer*   offer   = ecore_wl2_dnd_selection_get(input);
-
-    ecore_wl2_offer_receive(offer, const_cast<char*>(*types));
-    ecore_wl2_display_flush(ecore_wl2_input_display_get(input));
-#else
     ecore_wl_dnd_selection_get(ecore_wl_input_get(), *types);
 #endif
+
+    Dali::ClipboardEventNotifier clipboardEventNotifier(Dali::ClipboardEventNotifier::Get());
+    if(clipboardEventNotifier)
+    {
+      clipboardEventNotifier.SetContent(mSendBuffer);
+      clipboardEventNotifier.EmitContentSelectedSignal();
+    }
   }
 
-  void ExcuteSend(void* event)
+  char* ExcuteSend(void* event)
   {
 #ifdef ECORE_WAYLAND2
     Ecore_Wl2_Event_Data_Source_Send* ev = reinterpret_cast<Ecore_Wl2_Event_Data_Source_Send*>(event);
 #else
-    Ecore_Wl_Event_Data_Source_Send*  ev = reinterpret_cast<Ecore_Wl_Event_Data_Source_Send*>(event);
+    Ecore_Wl_Event_Data_Source_Send*     ev = reinterpret_cast<Ecore_Wl_Event_Data_Source_Send*>(event);
 #endif
 
     if(ev->serial != mSerial)
     {
-      return;
+      return NULL;
     }
 
-    int         len_buf      = mSendBuffer.length() + 1; // we should consider the char* buffer length
+    int         len_buf      = mSendBuffer.length();
     int         len_remained = len_buf;
     int         len_written  = 0, ret;
-    const char* buf          = mSendBuffer.c_str(); // last char in the buffer must be \0
+    const char* buf          = mSendBuffer.c_str();
 
     while(len_written < len_buf)
     {
@@ -169,17 +171,18 @@ struct Clipboard::Impl
       len_remained -= ret;
     }
     close(ev->fd);
+    return NULL;
   }
 
-  void ExcuteReceive(void* event, char*& data, int& length)
+  char* ExcuteReceive(void* event)
   {
 #ifdef ECORE_WAYLAND2
-    Ecore_Wl2_Event_Offer_Data_Ready* ev = reinterpret_cast<Ecore_Wl2_Event_Offer_Data_Ready*>(event);
+    Ecore_Wl2_Event_Selection_Data_Ready* ev = reinterpret_cast<Ecore_Wl2_Event_Selection_Data_Ready*>(event);
 #else
     Ecore_Wl_Event_Selection_Data_Ready* ev = reinterpret_cast<Ecore_Wl_Event_Selection_Data_Ready*>(event);
 #endif
-    data   = reinterpret_cast<char*>(ev->data);
-    length = ev->len;
+
+    return reinterpret_cast<char*>(ev->data);
   }
 
   int GetCount()
@@ -359,14 +362,9 @@ bool Clipboard::IsVisible() const
   return mImpl->IsVisible();
 }
 
-void Clipboard::ExcuteSend(void* event)
-{
-  mImpl->ExcuteSend(event);
-}
-
-void Clipboard::ExcuteReceive(void* event, char*& data, int& length)
+char* Clipboard::ExcuteBuffered(bool type, void* event)
 {
-  mImpl->ExcuteReceive(event, data, length);
+  return (type ? mImpl->ExcuteSend(event) : mImpl->ExcuteReceive(event));
 }
 
 } // namespace Adaptor
index 807f9db..070974f 100644 (file)
@@ -222,26 +222,26 @@ bool Clipboard::IsVisible() const
   return false;
 }
 
-void Clipboard::ExcuteSend(void* event)
+char* Clipboard::ExcuteBuffered(bool type, void* event)
 {
-}
-
-void Clipboard::ExcuteReceive(void* event, char*& data, int& length)
-{
-  // Receive
-  Ecore_X_Event_Selection_Notify* selectionNotifyEvent = static_cast<Ecore_X_Event_Selection_Notify*>(event);
-
-  Ecore_X_Selection_Data* selectionData = static_cast<Ecore_X_Selection_Data*>(selectionNotifyEvent->data);
-  if(selectionData->data)
+  if(!type)
   {
-    if(selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY)
+    // Receive
+    Ecore_X_Event_Selection_Notify* selectionNotifyEvent = static_cast<Ecore_X_Event_Selection_Notify*>(event);
+
+    Ecore_X_Selection_Data* selectionData = static_cast<Ecore_X_Selection_Data*>(selectionNotifyEvent->data);
+    if(selectionData->data)
     {
-      // Claim the ownership of the SECONDARY selection.
-      ecore_x_selection_secondary_set(mImpl->mApplicationWindow, "", 1);
-      data = reinterpret_cast<char*>(selectionData->data);
-      length = selectionData->length;
+      if(selectionNotifyEvent->selection == ECORE_X_SELECTION_SECONDARY)
+      {
+        // Claim the ownership of the SECONDARY selection.
+        ecore_x_selection_secondary_set(mImpl->mApplicationWindow, "", 1);
+
+        return (reinterpret_cast<char*>(selectionData->data));
+      }
     }
   }
+  return NULL;
 }
 
 } // namespace Adaptor
index 67a97d8..cf1fb78 100644 (file)
@@ -168,7 +168,7 @@ void EventHandler::OnSelectionDataSend(void* event)
   if(clipboard)
   {
     Clipboard& clipBoardImpl(GetImplementation(clipboard));
-    clipBoardImpl.ExcuteSend(event);
+    clipBoardImpl.ExcuteBuffered(true, event);
   }
 }
 
@@ -177,11 +177,10 @@ void EventHandler::OnSelectionDataReceived(void* event)
   // We have got the selected content, inform the clipboard event listener (if we have one).
   Dali::Clipboard clipboard     = Clipboard::Get();
   char*           selectionData = NULL;
-  int             bufferLength  = 0;
   if(clipboard)
   {
     Clipboard& clipBoardImpl(GetImplementation(clipboard));
-    clipBoardImpl.ExcuteReceive(event, selectionData, bufferLength);
+    selectionData = clipBoardImpl.ExcuteBuffered(false, event);
   }
 
   if(!mClipboardEventNotifier)
@@ -189,15 +188,15 @@ void EventHandler::OnSelectionDataReceived(void* event)
     mClipboardEventNotifier = ClipboardEventNotifier::Get();
   }
 
-  if(selectionData && mClipboardEventNotifier && bufferLength > 0)
+  if(selectionData && mClipboardEventNotifier)
   {
     ClipboardEventNotifier& clipboardEventNotifier(ClipboardEventNotifier::GetImplementation(mClipboardEventNotifier));
-    std::string             content(selectionData, bufferLength - 1);
+    std::string             content(selectionData, strlen(selectionData));
 
     clipboardEventNotifier.SetContent(content);
     clipboardEventNotifier.EmitContentSelectedSignal();
 
-    DALI_LOG_INFO(gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%s) strlen(%d) buffer(%d)\n", selectionData, strlen(selectionData), bufferLength);
+    DALI_LOG_INFO(gSelectionEventLogFilter, Debug::General, "EcoreEventSelectionNotify: Content(%d): %s\n", strlen(selectionData), selectionData);
   }
 }
 
index 278d13b..812ecfe 100644 (file)
@@ -964,7 +964,7 @@ void WindowBaseEcoreWl2::Initialize(PositionSize positionSize, Any surface, bool
 
   // Register Selection event - clipboard selection
   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this));
-  mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_OFFER_DATA_READY, EcoreEventDataReceive, this));
+  mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, this));
 
   // Register Effect Start/End event
   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_START, EcoreEventEffectStart, this));