1 /************************************************************
3 Copyright 1987, 1989, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ********************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
51 #include "windowstr.h"
52 #include "dixstruct.h"
54 #include "selection.h"
57 /*****************************************************************
62 * Selections are global to the server. The list of selections should
63 * not be traversed directly. Instead, use the functions listed above.
65 *****************************************************************/
67 Selection
*CurrentSelections
;
68 CallbackListPtr SelectionCallback
;
71 dixLookupSelection(Selection
** result
, Atom selectionName
,
72 ClientPtr client
, Mask access_mode
)
77 client
->errorValue
= selectionName
;
79 for (pSel
= CurrentSelections
; pSel
; pSel
= pSel
->next
)
80 if (pSel
->selection
== selectionName
)
84 rc
= XaceHookSelectionAccess(client
, &pSel
, access_mode
);
92 Selection
*pSel
, *pNextSel
;
94 pSel
= CurrentSelections
;
96 pNextSel
= pSel
->next
;
97 dixFreeObjectWithPrivates(pSel
, PRIVATE_SELECTION
);
101 CurrentSelections
= NULL
;
104 static _X_INLINE
void
105 CallSelectionCallback(Selection
* pSel
, ClientPtr client
,
106 SelectionCallbackKind kind
)
108 SelectionInfoRec info
= { pSel
, client
, kind
};
109 CallCallbacks(&SelectionCallback
, &info
);
113 DeleteWindowFromAnySelections(WindowPtr pWin
)
117 for (pSel
= CurrentSelections
; pSel
; pSel
= pSel
->next
)
118 if (pSel
->pWin
== pWin
) {
119 CallSelectionCallback(pSel
, NULL
, SelectionWindowDestroy
);
121 pSel
->pWin
= (WindowPtr
) NULL
;
123 pSel
->client
= NullClient
;
128 DeleteClientFromAnySelections(ClientPtr client
)
132 for (pSel
= CurrentSelections
; pSel
; pSel
= pSel
->next
)
133 if (pSel
->client
== client
) {
134 CallSelectionCallback(pSel
, NULL
, SelectionClientClose
);
136 pSel
->pWin
= (WindowPtr
) NULL
;
138 pSel
->client
= NullClient
;
143 ProcSetSelectionOwner(ClientPtr client
)
145 WindowPtr pWin
= NULL
;
150 REQUEST(xSetSelectionOwnerReq
);
151 REQUEST_SIZE_MATCH(xSetSelectionOwnerReq
);
154 time
= ClientTimeToServerTime(stuff
->time
);
156 /* If the client's time stamp is in the future relative to the server's
157 time stamp, do not set the selection, just return success. */
158 if (CompareTimeStamps(time
, currentTime
) == LATER
)
161 if (stuff
->window
!= None
) {
162 rc
= dixLookupWindow(&pWin
, stuff
->window
, client
, DixSetAttrAccess
);
166 if (!ValidAtom(stuff
->selection
)) {
167 client
->errorValue
= stuff
->selection
;
172 * First, see if the selection is already set...
174 rc
= dixLookupSelection(&pSel
, stuff
->selection
, client
, DixSetAttrAccess
);
177 /* If the timestamp in client's request is in the past relative
178 to the time stamp indicating the last time the owner of the
179 selection was set, do not set the selection, just return
181 if (CompareTimeStamps(time
, pSel
->lastTimeChanged
) == EARLIER
)
183 if (pSel
->client
&& (!pWin
|| (pSel
->client
!= client
))) {
185 .u
.selectionClear
.time
= time
.milliseconds
,
186 .u
.selectionClear
.window
= pSel
->window
,
187 .u
.selectionClear
.atom
= pSel
->selection
189 event
.u
.u
.type
= SelectionClear
;
190 WriteEventsToClient(pSel
->client
, 1, &event
);
193 else if (rc
== BadMatch
) {
195 * It doesn't exist, so add it...
197 pSel
= dixAllocateObjectWithPrivates(Selection
, PRIVATE_SELECTION
);
201 pSel
->selection
= stuff
->selection
;
203 /* security creation/labeling check */
204 rc
= XaceHookSelectionAccess(client
, &pSel
,
205 DixCreateAccess
| DixSetAttrAccess
);
211 pSel
->next
= CurrentSelections
;
212 CurrentSelections
= pSel
;
217 pSel
->lastTimeChanged
= time
;
218 pSel
->window
= stuff
->window
;
220 pSel
->client
= (pWin
? client
: NullClient
);
222 CallSelectionCallback(pSel
, client
, SelectionSetOwner
);
227 ProcGetSelectionOwner(ClientPtr client
)
231 xGetSelectionOwnerReply reply
;
233 REQUEST(xResourceReq
);
234 REQUEST_SIZE_MATCH(xResourceReq
);
236 if (!ValidAtom(stuff
->id
)) {
237 client
->errorValue
= stuff
->id
;
241 reply
= (xGetSelectionOwnerReply
) {
243 .sequenceNumber
= client
->sequence
,
247 rc
= dixLookupSelection(&pSel
, stuff
->id
, client
, DixGetAttrAccess
);
249 reply
.owner
= pSel
->window
;
250 else if (rc
== BadMatch
)
255 WriteReplyToClient(client
, sizeof(xGetSelectionOwnerReply
), &reply
);
260 ProcConvertSelection(ClientPtr client
)
268 REQUEST(xConvertSelectionReq
);
269 REQUEST_SIZE_MATCH(xConvertSelectionReq
);
271 rc
= dixLookupWindow(&pWin
, stuff
->requestor
, client
, DixSetAttrAccess
);
275 paramsOkay
= ValidAtom(stuff
->selection
) && ValidAtom(stuff
->target
);
276 paramsOkay
&= (stuff
->property
== None
) || ValidAtom(stuff
->property
);
278 client
->errorValue
= stuff
->property
;
282 rc
= dixLookupSelection(&pSel
, stuff
->selection
, client
, DixReadAccess
);
284 memset(&event
, 0, sizeof(xEvent
));
285 if (rc
!= Success
&& rc
!= BadMatch
)
287 else if (rc
== Success
&& pSel
->window
!= None
) {
288 event
.u
.u
.type
= SelectionRequest
;
289 event
.u
.selectionRequest
.owner
= pSel
->window
;
290 event
.u
.selectionRequest
.time
= stuff
->time
;
291 event
.u
.selectionRequest
.requestor
= stuff
->requestor
;
292 event
.u
.selectionRequest
.selection
= stuff
->selection
;
293 event
.u
.selectionRequest
.target
= stuff
->target
;
294 event
.u
.selectionRequest
.property
= stuff
->property
;
295 if (pSel
->client
&& pSel
->client
!= serverClient
&&
296 !pSel
->client
->clientGone
) {
297 WriteEventsToClient(pSel
->client
, 1, &event
);
302 event
.u
.u
.type
= SelectionNotify
;
303 event
.u
.selectionNotify
.time
= stuff
->time
;
304 event
.u
.selectionNotify
.requestor
= stuff
->requestor
;
305 event
.u
.selectionNotify
.selection
= stuff
->selection
;
306 event
.u
.selectionNotify
.target
= stuff
->target
;
307 event
.u
.selectionNotify
.property
= None
;
308 WriteEventsToClient(client
, 1, &event
);