Clear system clipboard using GTK lib, in C

I call the following function to try to clear the system clipboard:

GtkClipboard *clipboard;

clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_clear(clipboard);

however, he does not clean anything. I was looking for Gnome and GTK + documentation and lots of code snippets, and I don't know how to do this.

so my question is how do you clear the clipboard (linux, gnome) by code? Thank!

+3
source share
1 answer

I believe that you need to actually install it with zero-length text in order to completely clear it, I'm not sure why this is necessary, but this code works:

clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);                                                            
gtk_clipboard_clear(clipboard);                                                                                  
gtk_clipboard_set_text(clipboard, "", 0);                                                                        

clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);                                                          
gtk_clipboard_clear(clipboard);                                                                                
gtk_clipboard_set_text(clipboard, "", 0);

, GTK + X11, " ", GTK (GDK_SELECTION_CLIPBOARD) X11 (GDK_SELECTION_PRIMARY). Windows, GDK_SELECTION_PRIMARY, , .

+2

Source: https://habr.com/ru/post/1736342/


All Articles