using X clipboard for simple text copy/paste

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

 



I am trying to copy and paste text to the X clipboard, and that should be a really simple process, but the documentation:

is very abstract, and with no examples.  Please add examples to the documentation if possible.

This page has some good start info:

http://www.microimages.com/mix/clipprog.htm

--------
   Atom XA_UTF8 = XInternAtom(display, "UTF8", 0);
   Atom XA_UNICODE = XInternAtom(display, "UNICODE", 0);
   Atom XA_CLIPBOARD = XInternAtom(display, "CLIPBOARD", 0);

This declares two Atoms to use. Now, to put something on the Windows clipboard, call...

   XChangeProperty(display, RootWindow(display, 0), XA_CLIPBOARD, XA_UTF8, 8, PropModeReplace, buf, strlen(buf) + 1);
	

If the text you're placing on the clipboard is Unicode instead of UTF8, pass 16 for the 5th parameter and be sure to use wcstrlen() instead of strlen(). The length is still number of characters, not bytes.

To get text off the Windows clipboard, call...

   Atom actual_type;
   int actual_format;
   unsigned long nitems, leftover;
   unsigned char* buf;

   if (XGetWindowProperty(display, RootWindow(display,0), XA_CLIPBOARD, 0, 10000000L, False, XA_UTF8, &actual_type, &actual_format, &nitems, &leftover, &buf) == Success) {;
      /* Use buf */
      free(buf);
      }
-------------	
XA_CLIPBOARD should be in atoms.h with XA_PRIMARY, I think...

But the main thing is that when I do the:
   XChangeProperty(display, RootWindow(display, 0), XA_CLIPBOARD, XA_UTF8, 8, PropModeReplace, buf, strlen(buf) + 1);

I get a message from XClipboard, after a few seconds of delay that "XCLIPBOARD selection conversion failed".

What am I doing wrong?

thanks
Ted




-- 
Ted Huntington
Programmer Analyst I
Main Library
University of California, Irvine		
PO Box 19557
Irvine, CA 92623-9557
emesgs:  thunting@xxxxxxx
web page:  http://business.lib.uci.edu/webpages/ted.htm
8:00a-12:00p Business Office (949) 824-8926 
1:00p-5:00p  Multimedia Resource Center (949) 824-1674 
"Stop violence, teach science."

[Index of Archives]     [X Forum]     [Xorg]     [XFree86 Newbie]     [IETF Announce]     [Security]     [Font Config]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux Kernel]

  Powered by Linux