1
/* $Xorg: chgkbd.c,v 1.4 2001/02/09 02:04:33 xorgcvs Exp $ */
3
/************************************************************
5
Copyright 1989, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
27
Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
31
Permission to use, copy, modify, and distribute this software and its
32
documentation for any purpose and without fee is hereby granted,
33
provided that the above copyright notice appear in all copies and that
34
both that copyright notice and this permission notice appear in
35
supporting documentation, and that the name of Hewlett-Packard not be
36
used in advertising or publicity pertaining to distribution of the
37
software without specific, written prior permission.
39
HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
********************************************************/
48
/* $XFree86: xc/programs/Xserver/Xi/chgkbd.c,v 3.6 2001/12/14 19:58:54 dawes Exp $ */
50
/***********************************************************************
52
* Extension function to change the keyboard device.
58
#include "X.h" /* for inputstr.h */
59
#include "Xproto.h" /* Request macro */
60
#include "inputstr.h" /* DeviceIntPtr */
65
#include "extnsionst.h"
66
#include "extinit.h" /* LookupDeviceIntRec */
69
#include "exglobals.h"
74
/***********************************************************************
76
* This procedure changes the keyboard device.
81
SProcXChangeKeyboardDevice(client)
82
register ClientPtr client;
86
REQUEST(xChangeKeyboardDeviceReq);
87
swaps(&stuff->length, n);
88
REQUEST_SIZE_MATCH(xChangeKeyboardDeviceReq);
89
return(ProcXChangeKeyboardDevice(client));
92
/***********************************************************************
94
* This procedure is invoked to swap the request bytes if the server and
95
* client have a different byte order.
100
ProcXChangeKeyboardDevice (client)
101
register ClientPtr client;
104
DeviceIntPtr xkbd = inputInfo.keyboard;
106
FocusClassPtr xf = xkbd->focus;
109
xChangeKeyboardDeviceReply rep;
110
changeDeviceNotify ev;
112
REQUEST(xChangeKeyboardDeviceReq);
113
REQUEST_SIZE_MATCH(xChangeKeyboardDeviceReq);
115
rep.repType = X_Reply;
116
rep.RepType = X_ChangeKeyboardDevice;
118
rep.sequenceNumber = client->sequence;
120
dev = LookupDeviceIntRec (stuff->deviceid);
124
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
133
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
138
if (((dev->grab) && !SameClient(dev->grab, client)) ||
139
((xkbd->grab) && !SameClient(xkbd->grab, client)))
140
rep.status = AlreadyGrabbed;
141
else if ((dev->sync.frozen &&
142
dev->sync.other && !SameClient(dev->sync.other, client)) ||
143
(xkbd->sync.frozen &&
144
xkbd->sync.other && !SameClient(xkbd->sync.other, client)))
145
rep.status = GrabFrozen;
148
if (ChangeKeyboardDevice (xkbd, dev) != Success)
150
SendErrorToClient(client, IReqCode, X_ChangeKeyboardDevice, 0,
155
InitFocusClassDeviceStruct (dev);
157
InitKbdFeedbackClassDeviceStruct(dev, (BellProcPtr)NoopDDA,
158
(KbdCtrlProcPtr)NoopDDA);
161
df->revert = xf->revert;
163
df->traceGood = xf->traceGood;
164
if (df->traceSize != xf->traceSize)
166
Must_have_memory = TRUE; /* XXX */
167
df->trace = (WindowPtr *) xrealloc(df->trace,
168
xf->traceSize * sizeof(WindowPtr));
169
Must_have_memory = FALSE; /* XXX */
171
df->traceSize = xf->traceSize;
172
for (i=0; i<df->traceSize; i++)
173
df->trace[i] = xf->trace[i];
174
RegisterOtherDevice (xkbd);
175
RegisterKeyboardDevice (dev);
177
ev.type = ChangeDeviceNotify;
178
ev.deviceid = stuff->deviceid;
179
ev.time = currentTime.milliseconds;
180
ev.request = NewKeyboard;
182
SendEventToAllWindows (dev, ChangeDeviceNotifyMask, (xEvent *)&ev, 1);
183
SendMappingNotify (MappingKeyboard, k->curKeySyms.minKeyCode,
184
k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode + 1,client);
189
WriteReplyToClient (client, sizeof (xChangeKeyboardDeviceReply),
194
/***********************************************************************
196
* This procedure writes the reply for the XChangeKeyboardDevice
197
* function, if the client and server have a different byte ordering.
202
SRepXChangeKeyboardDevice (client, size, rep)
205
xChangeKeyboardDeviceReply *rep;
209
swaps(&rep->sequenceNumber, n);
210
swapl(&rep->length, n);
211
WriteToClient(client, size, (char *)rep);