Re: [Usability] clipboard manager comments

On Wed, Oct 16, 2002 at 07:24:45PM +0200, Philip Van Hoof wrote:
> On Wed, 2002-10-16 at 04:11, Gregory Merchan wrote:
> > The convention for a unique clipboard is to manage the selection
> > CLIPBOARD_MANAGER.  The details of this are in the ICCCM.
> This issue is fixed in cvs, I hope this code does the check correctly :
>   {
> 	GdkAtom manager = gdk_atom_intern("CLIPBOARD_MANAGER", FALSE);
> 	if (XGetSelectionOwner(gdk_display, (Atom) manager)) {
> 		g_print(_("GCM: another application that does clipboard "
>                         "management is already running\n"));
> 		exit(0);
> 	} else {
> 		gtk_selection_owner_set (GTK_WIDGET(mwin), manager,
> 	}
>   }

(I broke the string to make that fit 80 columns.)

GdkAtom and Atom are no longer the same type. You'll need to do:

  XGetSelectionOwner (gdk_display, gdk_x11_atom_to_xatom (manager));

It's an OK check. You could try to find a name for the existing owner
and present an alert to allow the user to replace the existing clipboard
manager (CM). If the existing manager is also GCM, you could either exit
quietly or pop up whatever window GCM might display. Another thing you
might do is wait until the existing CM gives up CLIPBOARD_MANAGER; that's
probably too messy with too little benefit.

When you claim the selection, you need to be sure to do so with the
server time. GTK may handle this itself when you pass GDK_CURRENT_TIME,
but check. If it doesn't, then you need to call gdk_x11_get_server_time().
Something like this:

  guint32 server_time;

  gtk_widget_add_events (GTK_WIDGET (mwin), GDK_PROPERTY_CHANGE_MASK);
  server_time = gdk_x11_get_server_time (GTK_WIDGET (mwin)->window);

  gtk_selection_owner_set (GTK_WIDGET (mwin), manager, server_time);

Once you've done that, you need to make sure it worked. Call
 XGetSelectionOwner() again and compare to the X window of the GdkWindow
 of your widget.

If it worked, you need to send an event to the root window; this is required
for all selection managers. It allows programs which may be interested in
the selection manager starting to know it has done so.

Of course, if you lose the CLIPBOARD_MANAGER selection you need to either
exit or start over.

Greg Merchan

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]