Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /* |
2 | * Copyright 2008 Red Hat, Inc. | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
21 | * DEALINGS IN THE SOFTWARE. | |
22 | * | |
23 | * Author: Peter Hutterer | |
24 | */ | |
25 | /*********************************************************************** | |
26 | * | |
27 | * Request to set and get an input device's focus. | |
28 | * | |
29 | */ | |
30 | ||
31 | #ifdef HAVE_DIX_CONFIG_H | |
32 | #include <dix-config.h> | |
33 | #endif | |
34 | ||
35 | #include "inputstr.h" /* DeviceIntPtr */ | |
36 | #include "windowstr.h" /* window structure */ | |
37 | #include <X11/extensions/XI2.h> | |
38 | #include <X11/extensions/XI2proto.h> | |
39 | ||
40 | #include "exglobals.h" /* BadDevice */ | |
41 | #include "xisetdevfocus.h" | |
42 | ||
43 | int | |
44 | SProcXISetFocus(ClientPtr client) | |
45 | { | |
46 | REQUEST(xXISetFocusReq); | |
47 | swaps(&stuff->length); | |
48 | swaps(&stuff->deviceid); | |
49 | swapl(&stuff->focus); | |
50 | swapl(&stuff->time); | |
51 | ||
52 | return ProcXISetFocus(client); | |
53 | } | |
54 | ||
55 | int | |
56 | SProcXIGetFocus(ClientPtr client) | |
57 | { | |
58 | REQUEST(xXIGetFocusReq); | |
59 | swaps(&stuff->length); | |
60 | swaps(&stuff->deviceid); | |
61 | ||
62 | return ProcXIGetFocus(client); | |
63 | } | |
64 | ||
65 | int | |
66 | ProcXISetFocus(ClientPtr client) | |
67 | { | |
68 | DeviceIntPtr dev; | |
69 | int ret; | |
70 | ||
71 | REQUEST(xXISetFocusReq); | |
72 | REQUEST_AT_LEAST_SIZE(xXISetFocusReq); | |
73 | ||
74 | ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetFocusAccess); | |
75 | if (ret != Success) | |
76 | return ret; | |
77 | if (!dev->focus) | |
78 | return BadDevice; | |
79 | ||
80 | return SetInputFocus(client, dev, stuff->focus, RevertToParent, | |
81 | stuff->time, TRUE); | |
82 | } | |
83 | ||
84 | int | |
85 | ProcXIGetFocus(ClientPtr client) | |
86 | { | |
87 | xXIGetFocusReply rep; | |
88 | DeviceIntPtr dev; | |
89 | int ret; | |
90 | ||
91 | REQUEST(xXIGetFocusReq); | |
92 | REQUEST_AT_LEAST_SIZE(xXIGetFocusReq); | |
93 | ||
94 | ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetFocusAccess); | |
95 | if (ret != Success) | |
96 | return ret; | |
97 | if (!dev->focus) | |
98 | return BadDevice; | |
99 | ||
100 | rep = (xXIGetFocusReply) { | |
101 | .repType = X_Reply, | |
102 | .RepType = X_XIGetFocus, | |
103 | .sequenceNumber = client->sequence, | |
104 | .length = 0 | |
105 | }; | |
106 | ||
107 | if (dev->focus->win == NoneWin) | |
108 | rep.focus = None; | |
109 | else if (dev->focus->win == PointerRootWin) | |
110 | rep.focus = PointerRoot; | |
111 | else if (dev->focus->win == FollowKeyboardWin) | |
112 | rep.focus = FollowKeyboard; | |
113 | else | |
114 | rep.focus = dev->focus->win->drawable.id; | |
115 | ||
116 | WriteReplyToClient(client, sizeof(xXIGetFocusReply), &rep); | |
117 | return Success; | |
118 | } | |
119 | ||
120 | void | |
121 | SRepXIGetFocus(ClientPtr client, int len, xXIGetFocusReply * rep) | |
122 | { | |
123 | swaps(&rep->sequenceNumber); | |
124 | swapl(&rep->length); | |
125 | swapl(&rep->focus); | |
126 | WriteToClient(client, len, rep); | |
127 | } |