1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
27 #include <dix-config.h>
33 #include <X11/Xproto.h>
34 #include <X11/keysym.h>
36 #include "dix/input_priv.h"
37 #include "xkb/xkbsrv_priv.h"
46 XkbProcessKeyboardEvent(DeviceEvent
*event
, DeviceIntPtr keybd
)
48 KeyClassPtr keyc
= keybd
->key
;
55 key
= event
->detail
.key
;
56 if (xkbDebugFlags
& 0x8)
57 DebugF("[xkb] XkbPKE: Key %d %s\n", key
,
58 (event
->type
== ET_KeyPress
? "down" : "up"));
60 if (xkbi
->repeatKey
== key
&& event
->type
== ET_KeyRelease
&&
61 !(xkbi
->desc
->ctrls
->enabled_ctrls
& XkbRepeatKeysMask
))
62 AccessXCancelRepeatKey(xkbi
, key
);
64 behavior
= xkbi
->desc
->server
->behaviors
[key
];
65 /* The "permanent" flag indicates a hard-wired behavior that occurs */
66 /* below XKB, such as a key that physically locks. XKB does not */
67 /* do anything to implement the behavior, but it *does* report that */
68 /* key is hardwired */
70 if (!keybd
->ignoreXkbActionsBehaviors
&& !(behavior
.type
& XkbKB_Permanent
)) {
71 switch (behavior
.type
) {
73 /* Neither of these should happen in practice, but ignore them
75 if (event
->type
== ET_KeyPress
&& !event
->key_repeat
&&
76 key_is_down(keybd
, key
, KEY_PROCESSED
))
78 else if (event
->type
== ET_KeyRelease
&&
79 !key_is_down(keybd
, key
, KEY_PROCESSED
))
83 if (event
->type
== ET_KeyRelease
)
85 else if (key_is_down(keybd
, key
, KEY_PROCESSED
))
86 event
->type
= ET_KeyRelease
;
88 case XkbKB_RadioGroup
:
89 ndx
= (behavior
.data
& (~XkbKB_RGAllowNone
));
90 if (ndx
< xkbi
->nRadioGroups
) {
93 if (event
->type
== ET_KeyRelease
)
96 rg
= &xkbi
->radioGroups
[ndx
];
97 if (rg
->currentDown
== event
->detail
.key
) {
98 if (behavior
.data
& XkbKB_RGAllowNone
) {
99 event
->type
= ET_KeyRelease
;
100 XkbHandleActions(keybd
, keybd
, event
);
105 if (rg
->currentDown
!= 0) {
106 int tmpkey
= event
->detail
.key
;
108 event
->type
= ET_KeyRelease
;
109 event
->detail
.key
= rg
->currentDown
;
110 XkbHandleActions(keybd
, keybd
, event
);
111 event
->type
= ET_KeyPress
;
112 event
->detail
.key
= tmpkey
;
114 rg
->currentDown
= key
;
117 ErrorF("[xkb] InternalError! Illegal radio group %d\n", ndx
);
123 unsigned overlay_active_now
;
124 unsigned is_keyrelease
= (event
->type
== ET_KeyRelease
) ? 1 : 0;
125 /* Remembers whether the key was pressed while overlay was down,
126 * for when overlay is already released, but the key is not. */
127 unsigned key_was_overlaid
= 0;
129 if (behavior
.type
== XkbKB_Overlay1
)
130 which
= XkbOverlay1Mask
;
132 which
= XkbOverlay2Mask
;
133 overlay_active_now
= (xkbi
->desc
->ctrls
->enabled_ctrls
& which
) ? 1 : 0;
135 if ((unsigned char)key
== key
) {
136 key_was_overlaid
= BitIsOn(xkbi
->overlay_perkey_state
, key
);
137 if (!is_keyrelease
) {
138 if (overlay_active_now
)
139 SetBit(xkbi
->overlay_perkey_state
, key
);
141 if (key_was_overlaid
)
142 ClearBit(xkbi
->overlay_perkey_state
, key
);
146 if ((overlay_active_now
|| key_was_overlaid
) &&
147 (behavior
.data
>= xkbi
->desc
->min_key_code
) &&
148 (behavior
.data
<= xkbi
->desc
->max_key_code
)) {
149 event
->detail
.key
= behavior
.data
;
154 ErrorF("[xkb] unknown key behavior 0x%04x\n", behavior
.type
);
158 XkbHandleActions(keybd
, keybd
, event
);
163 ProcessKeyboardEvent(InternalEvent
*ev
, DeviceIntPtr keybd
)
166 KeyClassPtr keyc
= keybd
->key
;
167 XkbSrvInfoPtr xkbi
= NULL
;
168 ProcessInputProc backup_proc
;
169 xkbDeviceInfoPtr xkb_priv
= XKBDEVICEINFO(keybd
);
170 DeviceEvent
*event
= &ev
->device_event
;
171 int is_press
= (event
->type
== ET_KeyPress
);
172 int is_release
= (event
->type
== ET_KeyRelease
);
174 /* We're only interested in key events. */
175 if (!is_press
&& !is_release
) {
176 UNWRAP_PROCESS_INPUT_PROC(keybd
, xkb_priv
, backup_proc
);
177 keybd
->public.processInputProc(ev
, keybd
);
178 COND_WRAP_PROCESS_INPUT_PROC(keybd
, xkb_priv
, backup_proc
,
183 xkbi
= keyc
->xkbInfo
;
185 /* If AccessX filters are active, then pass it through to
186 * AccessXFilter{Press,Release}Event; else, punt to
187 * XkbProcessKeyboardEvent.
189 * If AXF[PK]E don't intercept anything (which they probably won't),
190 * they'll punt through XPKE anyway. */
191 if ((xkbi
->desc
->ctrls
->enabled_ctrls
& XkbAllFilteredEventsMask
)) {
193 AccessXFilterPressEvent(event
, keybd
);
195 AccessXFilterReleaseEvent(event
, keybd
);
199 XkbProcessKeyboardEvent(event
, keybd
);