* * *

Author Topic: Copy-to-clipboard, text clears after exiting my app  (Read 1992 times)

Alextp

  • Sr. Member
  • ****
  • Posts: 413
    • UVViewSoft
Copy-to-clipboard, text clears after exiting my app
« on: March 07, 2017, 05:08:34 pm »
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

  • Hero Member
  • *****
  • Posts: 2674
    • Bart en Mariska's Webstek
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #1 on: March 07, 2017, 07:10:59 pm »
AFAIK this is standard *nix behaviour.

Bart

Alextp

  • Sr. Member
  • ****
  • Posts: 413
    • UVViewSoft
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #2 on: March 07, 2017, 08:34:54 pm »
GEdit does it ok: after exiting, it's clipboard text can be pasted.
How to do it?

Abelisto

  • Jr. Member
  • **
  • Posts: 63
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #3 on: March 07, 2017, 10:35:24 pm »
Code: Pascal  [Select]
  1. unit fix_gtk_clip;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.     gtk2, gdk2, Clipbrd;
  9.  
  10. implementation
  11.  
  12. var
  13.     c: PGtkClipboard;
  14.     t: string;
  15.  
  16. finalization
  17.     c := gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
  18.     t := Clipboard.AsText;
  19.     gtk_clipboard_set_text(c, PChar(t), Length(t));
  20.     gtk_clipboard_store(c);
  21. end.
Add this unit somewhere. It is dirty solution but it works for me.
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

Alextp

  • Sr. Member
  • ****
  • Posts: 413
    • UVViewSoft

Abelisto

  • Jr. Member
  • **
  • Posts: 63
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #5 on: March 08, 2017, 09:25:07 am »
There is another topic about the problem with some useful links: http://forum.lazarus.freepascal.org/index.php/topic,35244
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

KarenT

  • New member
  • *
  • Posts: 43
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #6 on: May 20, 2017, 09:02:25 pm »
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

  • Hero Member
  • *****
  • Posts: 1693
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #7 on: May 20, 2017, 09:06:46 pm »
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.
« Last Edit: May 20, 2017, 09:08:53 pm by molly »

Thaddy

  • Hero Member
  • *****
  • Posts: 4023
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #8 on: May 20, 2017, 09:33:31 pm »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

KarenT

  • New member
  • *
  • Posts: 43
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #9 on: May 20, 2017, 10:03:36 pm »
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]
  1. procedure TForm1.ed1Click(Sender: TObject);
  2. begin
  3.   (Sender as TEdit).SelectAll;
  4.   (Sender as TEdit).CopyToClipboard;
  5.   Timer1.Interval:=15000;
  6.   Timer1.Enabled:=True;
  7.   Hide;
  8. end;
  9.  
  10. procedure TForm1.Timer1Timer(Sender: TObject);
  11. begin
  12.   Close;
  13. end;
  14.  

Thaddy

  • Hero Member
  • *****
  • Posts: 4023
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #10 on: May 20, 2017, 10:12:32 pm »
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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

KarenT

  • New member
  • *
  • Posts: 43
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #11 on: May 21, 2017, 04:30:26 pm »
If 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

  • Full Member
  • ***
  • Posts: 118
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #12 on: May 21, 2017, 05:04:25 pm »

Thaddy

  • Hero Member
  • *****
  • Posts: 4023
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #13 on: May 21, 2017, 05:14:59 pm »
I 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.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

HeavyUser

  • Full Member
  • ***
  • Posts: 118
Re: Copy-to-clipboard, text clears after exiting my app
« Reply #14 on: May 21, 2017, 06:02:03 pm »
I 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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus