3 * x selection/cut buffer utility for Fvwm
5 * Copyright (c) 1999 Matthias Clasen <clasen@mathematik.uni-freiburg.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <X11/Xatom.h>
26 #include <X11/Intrinsic.h>
28 void paste_primary(Display
*dpy
, int window
, int property
, int delete)
32 unsigned long nitems
, bytes_after
, nread
;
33 unsigned char *data
, *d
, *h
, buf
[256];
37 window
= DefaultRootWindow (dpy
);
38 property
= XA_CUT_BUFFER0
;
46 if (XGetWindowProperty (dpy
, window
, property
, nread
/4, 1024L,
47 delete, AnyPropertyType
, &actual_type
,
48 &actual_format
, &nitems
, &bytes_after
,
49 (unsigned char **)&data
) != Success
)
51 if (actual_type
!= XA_STRING
)
54 /* send the text line-by-line, recognize continuation lines */
74 fprintf(stderr
, "xselection: line too long\n");
80 while (*h
== ' ') h
++;
91 } while (bytes_after
> 0);
94 int main (int argc
, char **argv
)
98 char *display_name
= NULL
;
102 if (!(dpy
= XOpenDisplay (display_name
)))
104 fprintf (stderr
, "xselection: can't open display %s\n",
105 XDisplayName (display_name
));
109 window
= XCreateSimpleWindow (dpy
, DefaultRootWindow(dpy
), 0,0,10,10, 0,0,0);
110 sel_property
= XInternAtom (dpy
, "VT_SELECTION", False
);
112 XConvertSelection (dpy
, XA_PRIMARY
, XA_STRING
, sel_property
, window
,
117 XNextEvent (dpy
, &event
);
118 if (event
.type
== SelectionNotify
)
120 paste_primary (dpy
, event
.xselection
.requestor
,
121 event
.xselection
.property
, True
);