Don't explicitly send MotionNotify event during Resize (GeometryWindow)
[fvwm.git] / utils / xselection.c
blob5d35c4c16a9f786c95a99bee1d916fcccd5e1365
1 /* -*-c-*- */
2 /*
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.
22 #include "config.h"
23 #include <stdio.h>
24 #include <X11/Xlib.h>
25 #include <X11/Xatom.h>
26 #include <X11/Intrinsic.h>
28 void paste_primary(Display *dpy, int window, int property, int delete)
30 Atom actual_type;
31 int actual_format;
32 unsigned long nitems, bytes_after, nread;
33 unsigned char *data, *d, *h, buf[256];
35 if (property == None)
37 window = DefaultRootWindow (dpy);
38 property = XA_CUT_BUFFER0;
39 delete = False;
42 nread = 0;
43 h = buf;
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)
50 return;
51 if (actual_type != XA_STRING)
52 return;
54 /* send the text line-by-line, recognize continuation lines */
55 d = data;
56 while (1) {
57 switch (*d) {
58 case '\n':
59 *h = 0;
60 break;
61 case '\\':
62 if (d[1] == '\n')
64 *h = ' ';
65 d++;
66 break;
68 /* fall through */
69 default:
70 *h = *d;
72 if (h - buf == 255)
74 fprintf(stderr, "xselection: line too long\n");
75 *h = 0;
77 if (*h == 0)
79 h = buf;
80 while (*h == ' ') h++;
81 printf ("%s\n", h);
82 h = buf;
84 else h++;
85 if (*d == 0) break;
86 d++;
89 nread += nitems;
90 XFree (data);
91 } while (bytes_after > 0);
94 int main (int argc, char **argv)
96 XEvent event;
97 Atom sel_property;
98 char *display_name = NULL;
99 Display *dpy;
100 Window window;
102 if (!(dpy = XOpenDisplay (display_name)))
104 fprintf (stderr, "xselection: can't open display %s\n",
105 XDisplayName (display_name));
106 exit (1);
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,
113 CurrentTime);
115 while (1)
117 XNextEvent (dpy, &event);
118 if (event.type == SelectionNotify)
120 paste_primary (dpy, event.xselection.requestor,
121 event.xselection.property, True);
122 exit (0);