[Done] - PB6.00 LTS - Set/GetClipboardText() not working

Post bugreports for the Linux version here
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

[Done] - PB6.00 LTS - Set/GetClipboardText() not working

Post by NicTheQuick »

Hi,

somehow SetClipboardText() and GetClipboardText() are not working anymore on my Ubuntu 22.04 LTS.

I can set something to it and get it again but I can not paste it with CTRL+V or copy something with CTRL+C. It seems it uses some hidden clipboard which the normal GUI has no access to.

Code: Select all

i.i = Random(100)
SetClipboardText(Str(i))

Debug i
Debug GetClipboardText()
With the subsystem gtk2 I at least can get the content of my actual clipboard with GetClipboardText() but I can not set it.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
mk-soft
Always Here
Always Here
Posts: 5334
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB6.00 LTS] Set/GetClipboardText() not working

Post by mk-soft »

Interesting and typically Linux,

Set/GetClipboardText must be processed with EventLoop, otherwise the whole clipboard of Linux hangs.
Geteset with Ubuntu 20.04 and 22.04, PB v5.73 and v6.00

Code: Select all

;-TOP

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButtonCopy
  #MainButtonPaste
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar)
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx -10, dy - 45)
  ResizeGadget(#MainButtonCopy, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButtonPaste, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, "Window" , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar)
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonCopy, 10, dy - 35, 120, 30, "Copy")
    ButtonGadget(#MainButtonPaste, dx - 130, dy - 35, 120, 30, "Paste")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Break
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
              
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
              EndSelect
              
            Case #MainButtonCopy
              Select EventType()
                Case #PB_EventType_LeftClick
                  SetClipboardText(GetGadgetText(#MainEdit))
                  
              EndSelect
              
            Case #MainButtonPaste
              Select EventType()
                Case #PB_EventType_LeftClick
                  AddGadgetItem(#MainEdit, -1, GetClipboardText())
                  
              EndSelect
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
P.S.
From Thread it doesn't work either, so I had added Set/GetClipboard to my ThreadToGUI at some point.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: [PB6.00 LTS] Set/GetClipboardText() not working

Post by NicTheQuick »

Wow, that's weird.
For some bash scripts I usually use xclip to set clipboard data or read from it. In its source it also uses a window to be able to use the clipboard:

Code: Select all

...
    /* Connect to the X server. */
    if ((dpy = XOpenDisplay(sdisp))) {
	/* successful */
	if (fverb == OVERBOSE)
	    fprintf(stderr, "Connected to X server.\n");
    }
    else {
	/* couldn't connect to X server. Print error and exit */
	errxdisplay(sdisp);
    }

    /* parse selection command line option */
    doOptSel();

    /* parse noutf8 and target command line options */
    doOptTarget();

    /* Create a window to trap events */
    win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, 0, 0);

    /* get events about property changes */
    XSelectInput(dpy, win, PropertyChangeMask);

    if (fdiri)
	exit_code = doIn(win, argv[0]);
    else
	exit_code = doOut(win);

    /* Disconnect from the X server */
    XCloseDisplay(dpy);
...
I don't know what Purebasic but it would be nice if this just works without a window because it also did before.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
mk-soft
Always Here
Always Here
Posts: 5334
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB6.00 LTS] Set/GetClipboardText() not working

Post by mk-soft »

I don't know what Purebasic but it would be nice if this just works without a window because it also did before.
PB v5.73 not work too without event loop.

xclip uses X11 library.
So also X11 Event management ;)

Maybe use a hidden window.

Code: Select all

hideWindow = OpenWindow(#PB_Any, 0, 0, 0, 0, "XClipboard", #PB_Window_Invisible | #PB_Window_NoGadgets)
i.i = Random(100)
SetClipboardText("Value: " + Str(i))
While WindowEvent() : Wend

Debug i
Debug GetClipboardText()
While WindowEvent() : Wend
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
NicTheQuick
Addict
Addict
Posts: 1224
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: [PB6.00 LTS] Set/GetClipboardText() not working

Post by NicTheQuick »

If the difference is not the Purebasic version then it is because I recently upgraded to Ubuntu 22.04. I've got no older Ubuntu here to check again.
Still a bug in my opinion.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
User avatar
mk-soft
Always Here
Always Here
Posts: 5334
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [PB6.00 LTS] Set/GetClipboardText() not working

Post by mk-soft »

Tested now with PB v5.73 and v6.00 without window and event loop ...

Ubuntu 18.04 - work
Ubuntu 20.04 - failed
Ubuntu 22.04 - failed
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Fred
Administrator
Administrator
Posts: 16617
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [PB6.00 LTS] Set/GetClipboardText() not working

Post by Fred »

Fixed.
Post Reply