Hello, All!

Is it any nice way to change current selection value in my client and
then and there paste it to another application (for example, xterm)?

My code don't want to work

int change_and_paste_sel(Display* dpy, Window xterm)
{
Window win, selown;
Atom type;
int format;
long len, bytes_left, dummy;
XEvent ev;

win = XCreateSimpleWindow(dpy,
RootWindow(dpy, DefaultScreen(dpy)), 0, 0, 100, 100, 1, 0, 0);
XFlush(dpy);
XSelectInput(dpy, win, StructureNotifyMask);

selown = XSetSelectionOwner(dpy, XA_PRIMARY, win, CurrentTime);

if (selown != None) {
XChangeProperty(dpy, win, XA_PRIMARY, XA_STRING, 8,
PropModeReplace, "New Selection Value", 8);

ev.xkey.window = xterm;
ev.xkey.root = DefaultRootWindow(dpy);
ev.xkey.subwindow = None;
ev.xkey.time = CurrentTime;
ev.xkey.x = ev.xkey.y = ev.xkey.x_root = ev.xkey.y_root = 1;
ev.xkey.state = ShiftMask;
ev.xkey.same_screen = True;

ev.xkey.keycode = XKeysymToKeycode(dpy, XK_Insert);

ev.type = KeyPress;
XSendEvent(dpy, xterm, True, KeyPressMask, &ev);
ev.type = KeyRelease;
XSendEvent(dpy, xterm, True, KeyReleaseMask, &ev);

XFlush(dpy);
return 1;
}

return 0;
}

--
With best regards
Templar