From 9f9e584919aefbd1f9911c22e6d72308d81785a2 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Fri, 24 Mar 2023 16:56:25 +0100 Subject: [PATCH] Wayland Fl_Copy_Surface and Fl::copy() issues (#707) - cont'd --- README.Wayland.txt | 6 ++++++ src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.Wayland.txt b/README.Wayland.txt index 98efcd5cd..c755a656a 100644 --- a/README.Wayland.txt +++ b/README.Wayland.txt @@ -96,6 +96,12 @@ a minimized window has no effect. it's currently not possible for an app to be notified of changes to the content of the system clipboard, that is, Fl::add_clipboard_notify() has no effect. +* Copying data to the clipboard is best done when the app has focus. Any copy operation +performed when the app not yet got the focus does not change the clipboard. A copy operation +performed when the app has lost the focus is successful only if the type of the copied +data, that is text or image, is the same as the last data type copied when the app had +the focus. + * Narrow windows with a titlebar are silently forced to be wide enough for the titlebar to display window buttons and a few letters of the title. diff --git a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx index 2c78d399c..535d481fc 100644 --- a/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx +++ b/src/drivers/Wayland/fl_wayland_clipboard_dnd.cxx @@ -77,13 +77,15 @@ void write_data_source_cb(FL_SOCKET fd, data_source_write_struct *data) { static void data_source_handle_send(void *data, struct wl_data_source *source, const char *mime_type, int fd) { fl_intptr_t rank = (fl_intptr_t)data; //fprintf(stderr, "data_source_handle_send: %s fd=%d l=%d\n", mime_type, fd, fl_selection_length[1]); - if (strcmp(mime_type, wld_plain_text_clipboard) == 0 || strcmp(mime_type, "text/plain") == 0 || strcmp(mime_type, "image/bmp") == 0) { + if (((!strcmp(mime_type, wld_plain_text_clipboard) || !strcmp(mime_type, "text/plain")) && fl_selection_type[rank] == Fl::clipboard_plain_text) + || + (!strcmp(mime_type, "image/bmp") && fl_selection_type[rank] == Fl::clipboard_image) ) { data_source_write_struct *write_data = new data_source_write_struct; write_data->rest = fl_selection_length[rank]; write_data->from = fl_selection_buffer[rank]; Fl::add_fd(fd, FL_WRITE, (Fl_FD_Handler)write_data_source_cb, write_data); } else { - Fl::error("Destination client requested unsupported MIME type: %s\n", mime_type); + //Fl::error("Destination client requested unsupported MIME type: %s\n", mime_type); close(fd); } }