Copy-to-clipboard, text clears after exiting my app lazarus / 66-Unix ---------------------------------------------------------------------- AlexTP · 2017-03-07 16:08 CudaText app (LCL, Linux gtk2) I copy text as Clipboard.AsText:= 'dddddddddddd'; after my app exits, other apps don't see this text. Clipboard empty. Why? ---------------------------------------------------------------------- Bart · 2017-03-07 18:10 AFAIK this is standard *nix behaviour. Bart ---------------------------------------------------------------------- AlexTP · 2017-03-07 19:34 GEdit does it ok: after exiting, it's clipboard text can be pasted. How to do it? ---------------------------------------------------------------------- Abelisto · 2017-03-07 21:35 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit fix_gtk_clip; {$mode objfpc}{$H+} interface uses    gtk2, gdk2, Clipbrd; implementation var    c: PGtkClipboard;    t: string; finalization    c := gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);    t := Clipboard.AsText;    gtk_clipboard_set_text(c, PChar(t), Length(t));    gtk_clipboard_store(c);end.Add this unit somewhere. It is dirty solution but it works for me. ---------------------------------------------------------------------- AlexTP · 2017-03-08 02:50 Thank you... Added code to wiki- http://wiki.freepascal.org/Clipboard#How_to_fix_empty_GTK2_clipboard_o n_exit ---------------------------------------------------------------------- Abelisto · 2017-03-08 08:25 There is another topic about the problem with some useful links: http://forum.lazarus.freepascal.org/index.php/topic,35244 ---------------------------------------------------------------------- KarenT · 2017-05-20 19:02 I am having this same problem. Tried in Ubuntu and Mint same - same. Clipboard is fine until I close the program. I added the fix_gtk_clip unit but still clipboard is cleared on exit. Any progress on this being made possible natively in Lazarus? ---------------------------------------------------------------------- molly · 2017-05-20 19:06 afai, the 'clearing' of the clipboard after program closes is up to the window manager in use. Some provide an additional (as in you are required to install one yourself) clipboard manager that solves that issue for you, others have a build in clipboard manager. Do a search on these forums, the question has been asked (and answered) multiple times. ---------------------------------------------------------------------- Thaddy · 2017-05-20 19:33 https://wiki.ubuntu.com/ClipboardPersistence Not only for Ubuntu. ---------------------------------------------------------------------- KarenT · 2017-05-20 20:03 Thanks, but I had read many links and tried them all before posting. Nothing is working, so came up with a kludge that suits me fine. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ed1Click(Sender: TObject);begin  (Sender as TEdit).SelectAll;  (Sender as TEdit).CopyToClipboard;  Timer1.Interval:=15000;  Timer1.Enabled:=True;  Hide;end; procedure TForm1.Timer1Timer(Sender: TObject);begin  Close;end; ---------------------------------------------------------------------- Thaddy · 2017-05-20 20:12 If that worked, try Application.ProcessMessages instead of the timer. The message queue is implemented differently on linux, so maybe the queue is not fully processed. ---------------------------------------------------------------------- KarenT · 2017-05-21 14:30 Quote from: Thaddy on May 20, 2017, 10:12:32 pmIf that worked, try Application.ProcessMessages instead of the timer. Thanks, but that did not make any difference either. Even using the "fix_gtk_clip" did not work. Stepping through it, the "t" in this "t := Clipboard.AsText;" was empty as it was closing down. The thing is, that many people have stated that other programs work fine with cut/paste without special Clipboard-Managers, so there must be a solution. The timer workaround is adequate for my needs right now, but it would be nice to not keep finding the frailties of using Linux and Lazarus. I wonder if Kylix is still available some where. ---------------------------------------------------------------------- HeavyUser · 2017-05-21 15:04 Quote from: KarenT on May 21, 2017, 04:30:26 pmI wonder if Kylix is still available some where. https://sourceforge.net/projects/freeclx/ ---------------------------------------------------------------------- Thaddy · 2017-05-21 15:14 Quote from: HeavyUser on May 21, 2017, 05:04:25 pmQuote from: KarenT on May 21, 2017, 04:30:26 pmI wonder if Kylix is still available some where. https://sourceforge.net/projects/freeclx/ That's just the libraries. Also note D7-D2007 code still contain CLX and can be massaged to work with FPC if you have an edition with sourcecode. ---------------------------------------------------------------------- HeavyUser · 2017-05-21 16:02 Quote from: Thaddy on May 21, 2017, 05:14:59 pmQuote from: HeavyUser on May 21, 2017, 05:04:25 pmQuote from: KarenT on May 21, 2017, 04:30:26 pmI wonder if Kylix is still available some where. https://sourceforge.net/projects/freeclx/ That's just the libraries. Also note D7-D2007 code still contain CLX and can be massaged to work with FPC if you have an edition with sourcecode. it should contain the clipboard code requested in this thread. Although, it is possible that the code is nothing more that a thin layer on top of the qt clipboard classes. ---------------------------------------------------------------------- KarenT · 2017-05-21 18:40 All too hard for the time I have available and the Timer is solving it fine. The program is for my own use so I can live with it until I see a native-working option for Linux/Lazarus. ---------------------------------------------------------------------- Leledumbo · 2017-05-21 19:11 Just install a clipboard manager. It's WM/DE problem, not application problem. ---------------------------------------------------------------------- Graeme · 2017-05-22 08:12 Quote from: KarenT on May 21, 2017, 04:30:26 pmI wonder if Kylix is still available some where. Yes, but I really wouldn't recommend using Kylix any more. It is just too out of date these days (compiler and IDE), and CLX uses a terribly old Qt (that just looks crap - doesn't even support anti-aliased text).    http://geldenhuys.co.uk/~graemeg/kylix3_openedition.tar.gz Rather use fpGUI or MSEgui for true cross-platform applications, or look at LCL with its inconsistencies across platforms. ---------------------------------------------------------------------- Graeme · 2017-05-22 08:24 Quote from: Alextp on March 07, 2017, 05:08:34 pmafter my app exits, other apps don't see this text. Clipboard empty. Why? It is standard X11 behaviour, and is actually more efficient than Windows clipboard. Why, because on Windows, if you copy something to the clipboard you instantly get a copy, and thus it uses memory (RAM) to store that copy. On X11 when you copy something to the clipboard, it simply notifies the windowing system of the window that has content available, but no copy actually exists in RAM yet. Once once a target applications requests that content (via a Paste action), does it query the source window/application for the contents. This explains why you clipboard is empty, because that source application has already terminated. Now some newer Window Managers in X11 support clipboard managers that can go against the X11 design. What these clipboard managers do, is become the "source" of the clipboard content, instead of the original source application. This clipboard managers keep running while the window manager runs, so you never get the "out of scope" situation. If you want to see the technical details in how this is implemented, so applications (actually the GUI framework) can take advantage of such clipboard managers, take a look at how it was implemented in fpGUI Toolkit. Quotecommit c2af2a386efef5d52db20482e81748fc36aedb91 Author: Andrew Haines Date:   Wed Apr 24 17:24:50 2013 +0200     Persistent clipboard support under X11.         Some desktop environments or window managers include support for a clipboard     manager. This clipboard manager can make the content of the clipboard persistent     even after the source application closed down. ---------------------------------------------------------------------- Thaddy · 2017-05-22 09:12 There is the small complication that keeping data on the clipboard after exiting a process is technically a memory leak. That's also the reason that X11 developers won't fix it. It is unsafe behavior. A clipboard manager merely takes ownership of the data but clipboards are inherently not secure unless the manager encrypts and decrypts the data. This is a known Windows design flaw, although even on Windows the clipboard data is only accessible locally after process termination. ---------------------------------------------------------------------- KarenT · 2017-05-22 16:58 Quote from: Leledumbo on May 21, 2017, 09:11:44 pmJust install a clipboard manager. It's WM/DE problem, not application problem. But, I shouldn't have to, gedit handles it and leaves text on the Clipboard after closing. But not an issue as I have mentioned, I'll just go with the Timer.