summaryrefslogtreecommitdiff
path: root/src/Fl_x.cxx
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2023-01-03 19:40:37 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2023-01-06 16:45:22 +0100
commit8dd3ff8e12a7cabce9a1931831b311bf898aaaaf (patch)
tree27d5e353daf6aaa795df3fb8046c2bf9f11775d0 /src/Fl_x.cxx
parent69773338b9bdd91c5f8e94400f68172ccfc098ac (diff)
X11: Optionally copy selection buffer to clipboard (STR 3229)
The new method Fl::selection_to_clipboard(int) enables copying selection data to the clipboard on X11 if it is set to 1. This feature was requested by STR 3229 and the implementation was inspired by an `xterm` feature named "Select to Clipboard" which can be enabled by 'ctrl + middle mouse button + "Select to Clipboard"' in an xterm window.
Diffstat (limited to 'src/Fl_x.cxx')
-rw-r--r--src/Fl_x.cxx14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index 2c2720033..14aacaa7b 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -1,7 +1,7 @@
//
// X specific code for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2022 by Bill Spitzak and others.
+// Copyright 1998-2023 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -807,13 +807,19 @@ static int get_xwinprop(Window wnd, Atom prop, long max_length,
////////////////////////////////////////////////////////////////
// Code for copying to clipboard and DnD out of the program:
+// See Fl::copy() for possible values of the destination (argument clipboard)
+// See also Fl::selection_to_clipboard()
void Fl_X11_Screen_Driver::copy(const char *stuff, int len, int clipboard, const char *type) {
if (!stuff || len<0) return;
+ // if selection_to_clipboard is enabled *and* destination is 0 (selection buffer),
+ // then copy to both (STR 3229)
+ if (clipboard == 0 && Fl::selection_to_clipboard())
+ clipboard = 2;
+
if (clipboard >= 2) {
- copy(stuff, len, 0, type);
- copy(stuff, len, 1, type);
- return;
+ copy(stuff, len, 1, type); // copy to clipboard first (this is a recursion!)
+ clipboard = 0; // ... and then to selection buffer: fall through
}
if (len+1 > fl_selection_buffer_length[clipboard]) {