[Mono-devel-list] Complex bug/issue in Gtk.Clipboard

Philip Van Hoof spamfrommailing at freax.org
Thu Jul 17 16:36:58 EDT 2003

Hi there,

During the rewrite of my clipboard manager code (which is written in C
using the plain C API of Gtk+) I spotted some very complex bugs in

The most important one is that setting a clipboard does not work. 

To set a clipboard, one must do this :

Clipboard.Set (targets, new Gtk.ClipboardGetFunc(GetFunc), new
Gtk.ClipboardClearFunc(ClearFunc), null))

Get GetFunc will be called when another Xclient requests the clipboard
and the ClearFunc will be called when the application calling this has
lost the ownership of the clipboard. (Since you guys -the ones on
gtk-sharp- are all GNOME developers I am pretty sure you all know this)

Those events work. So thats good, I guess.. However, it looks like there
is something wrong with the parameter "selection_data" that gets passed
by reference

This is the description of such a GetFunc-method :

void GetFunc(Clipboard clipboard, ref SelectionData selection_data, uint
info, object o)

First, selection_data is not always not null, which is wierd. Second
when you should in this method convert the data of the clipboard that
you want to give to the requesting XClient to the format it asked for,
it does not work.

If I read the gtk-sharp sources I understand one could do this using

selection_data.Text = "test"; This would make the XClient who requests
the clipboard paste "test", right? Well this does not work.

I did some detailled analysis using my old clipboard manager. It looks
like something actually does get set. But only targets like TIMESTAMP
and MULTIPLE convert the data to something different than NULL.

The UTF8_STRING, COMPOUND_TEXT, .. atoms all result in NULL being
received at the requesting XClient.

I have like .. turned the gtk-sharp code upside down in files like
GtkClipboardGetFuncNative, SelectionData.custom, retried, recompiled
gtk-sharp, debugged etc etc etc .. nothing got it actually working.

I also tried very very simple examples (I attached one) which also don't

IMHO this is a serious showstopper as this disables setting the
clipboard to somthing else than some stupid plain text clipboard in

Note that I have also tried calling the C-api of gtk+ directly just like
how gtk-sharp does it. In the attached example I am also doing this for
one particular function (else I cannot cast Atom to uint, maybe the Raw
member of all gtk-sharp objects should not be private for such advanced
casting to be possible)

ps. I am (always) using what is currently in CVS

Note that if you see a error in my example, and if you get it working :)
then this is nolonger a bugreport but my mistake. But I fear that it's a
gtk-sharp bug .. (again, I can be wrong).

Philip Van Hoof, Software Developer @ Cronos
home: me at freax dot org
work: Philip dot VanHoof at cronos dot be
http://www.freax.be, http://www.freax.eu.org
-------------- next part --------------
using Gtk;
using Gdk;
using Gnome;
using GtkSharp;
using System;
using System.Threading;
using System.Runtime.InteropServices;
using GLibSharp;
using GLib;

public class Test
	static extern IntPtr gdk_atom_intern(string atom_name, bool only_if_exists);

	public Test ()
		TargetEntry [] targets = new TargetEntry[1];
		targets[0].target = "COMPOUND_TEXT";
		targets[0].info = 0;
		targets[0].flags = (uint) gdk_atom_intern ("COMPOUND_TEXT", false);
		Gtk.Clipboard clipboard = Gtk.Clipboard.Get (Atom.Intern("CLIPBOARD", false));

		clipboard.Set (targets, new Gtk.ClipboardGetFunc(GetFunc), new Gtk.ClipboardClearFunc(ClearFunc), null);
		Console.WriteLine ("I now own the clipboardownership, waiting for a clipboard request");

	public void GetFunc(Clipboard clipboard, ref SelectionData selection_data, uint info, object o)
		Console.WriteLine ("Somebody wants me to give the clipboard");
		selection_data.Text = "test";

	public void ClearFunc (Clipboard clipboard, object o)
		Console.WriteLine ("I lost the clipboard ownership");

	static public void Main (string[] args)
		Program deamon = new Program ("Deamon", "0.1", Modules.UI, args);
		Application.Init ();
		Test t = new Test ();
		Application.Run ();

More information about the Mono-devel-list mailing list