]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/hw/vnc/cutpaste.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / hw / vnc / cutpaste.c
1 /*
2  * cutpaste.c - routines to deal with cut & paste buffers / selection.
3  */
4
5 /*
6  *  Copyright (C) 2002 RealVNC Ltd.
7  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
8  *
9  *  This is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This software is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this software; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
22  *  USA.
23  */
24
25 #include <stdio.h>
26 #define NEED_EVENTS
27 #include <X.h>
28 #include <Xproto.h>
29 #include "rfb.h"
30 #include "selection.h"
31 #include "input.h"
32 #include <property.h>
33 #include <Xatom.h>
34
35 extern WindowPtr *WindowTable; /* Why isn't this in a header file? */
36 extern Selection *CurrentSelections;
37 extern int NumCurrentSelections;
38
39
40 static Bool inSetXCutText = FALSE;
41
42 /*
43  * rfbSetXCutText sets the cut buffer to be the given string.  We also clear
44  * the primary selection.  Ideally we'd like to set it to the same thing, but I
45  * can't work out how to do that without some kind of helper X client.
46  */
47
48 void
49 rfbSetXCutText(char *str, int len)
50 {
51     int i = 0;
52
53     inSetXCutText = TRUE;
54     ChangeWindowProperty(WindowTable[0], XA_CUT_BUFFER0, XA_STRING,
55                          8, PropModeReplace, len,
56                          (pointer)str, TRUE);
57     
58     while ((i < NumCurrentSelections) && 
59            CurrentSelections[i].selection != XA_PRIMARY)
60         i++;
61
62     if (i < NumCurrentSelections) {
63         xEvent event;
64
65         if (CurrentSelections[i].client) {
66             event.u.u.type = SelectionClear;
67             event.u.selectionClear.time = GetTimeInMillis();
68             event.u.selectionClear.window = CurrentSelections[i].window;
69             event.u.selectionClear.atom = CurrentSelections[i].selection;
70             (void) TryClientEvents (CurrentSelections[i].client, &event, 1,
71                                 NoEventMask, NoEventMask /* CantBeFiltered */,
72                                 NullGrab);
73         }
74
75         CurrentSelections[i].window = None;
76         CurrentSelections[i].pWin = NULL;
77         CurrentSelections[i].client = NullClient;
78     }
79
80     inSetXCutText = FALSE;
81 }
82
83
84 void rfbGotXCutText(char *str, int len)
85 {
86     if (!inSetXCutText)
87         rfbSendServerCutText(str, len);
88 }