xkbPrKeyEv.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /************************************************************
  2. Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  3. Permission to use, copy, modify, and distribute this
  4. software and its documentation for any purpose and without
  5. fee is hereby granted, provided that the above copyright
  6. notice appear in all copies and that both that copyright
  7. notice and this permission notice appear in supporting
  8. documentation, and that the name of Silicon Graphics not be
  9. used in advertising or publicity pertaining to distribution
  10. of the software without specific prior written permission.
  11. Silicon Graphics makes no representation about the suitability
  12. of this software for any purpose. It is provided "as is"
  13. without any express or implied warranty.
  14. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  15. SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  16. AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  18. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  20. OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  21. THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. ********************************************************/
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <stdio.h>
  27. #include <math.h>
  28. #include <X11/X.h>
  29. #include <X11/Xproto.h>
  30. #include <X11/keysym.h>
  31. #include "misc.h"
  32. #include "inputstr.h"
  33. #include "exevents.h"
  34. #include "eventstr.h"
  35. #include <xkbsrv.h>
  36. #include <ctype.h>
  37. #include "events.h"
  38. /***====================================================================***/
  39. void
  40. XkbProcessKeyboardEvent(DeviceEvent *event, DeviceIntPtr keybd)
  41. {
  42. KeyClassPtr keyc = keybd->key;
  43. XkbSrvInfoPtr xkbi;
  44. int key;
  45. XkbBehavior behavior;
  46. unsigned ndx;
  47. xkbi = keyc->xkbInfo;
  48. key = event->detail.key;
  49. if (xkbDebugFlags & 0x8)
  50. DebugF("[xkb] XkbPKE: Key %d %s\n", key,
  51. (event->type == ET_KeyPress ? "down" : "up"));
  52. if (xkbi->repeatKey == key && event->type == ET_KeyRelease &&
  53. !(xkbi->desc->ctrls->enabled_ctrls & XkbRepeatKeysMask))
  54. AccessXCancelRepeatKey(xkbi, key);
  55. behavior = xkbi->desc->server->behaviors[key];
  56. /* The "permanent" flag indicates a hard-wired behavior that occurs */
  57. /* below XKB, such as a key that physically locks. XKB does not */
  58. /* do anything to implement the behavior, but it *does* report that */
  59. /* key is hardwired */
  60. if (!(behavior.type & XkbKB_Permanent)) {
  61. switch (behavior.type) {
  62. case XkbKB_Default:
  63. /* Neither of these should happen in practice, but ignore them
  64. anyway. */
  65. if (event->type == ET_KeyPress && !event->key_repeat &&
  66. key_is_down(keybd, key, KEY_PROCESSED))
  67. return;
  68. else if (event->type == ET_KeyRelease &&
  69. !key_is_down(keybd, key, KEY_PROCESSED))
  70. return;
  71. break;
  72. case XkbKB_Lock:
  73. if (event->type == ET_KeyRelease)
  74. return;
  75. else if (key_is_down(keybd, key, KEY_PROCESSED))
  76. event->type = ET_KeyRelease;
  77. break;
  78. case XkbKB_RadioGroup:
  79. ndx = (behavior.data & (~XkbKB_RGAllowNone));
  80. if (ndx < xkbi->nRadioGroups) {
  81. XkbRadioGroupPtr rg;
  82. if (event->type == ET_KeyRelease)
  83. return;
  84. rg = &xkbi->radioGroups[ndx];
  85. if (rg->currentDown == event->detail.key) {
  86. if (behavior.data & XkbKB_RGAllowNone) {
  87. event->type = ET_KeyRelease;
  88. XkbHandleActions(keybd, keybd, event);
  89. rg->currentDown = 0;
  90. }
  91. return;
  92. }
  93. if (rg->currentDown != 0) {
  94. int tmpkey = event->detail.key;
  95. event->type = ET_KeyRelease;
  96. event->detail.key = rg->currentDown;
  97. XkbHandleActions(keybd, keybd, event);
  98. event->type = ET_KeyPress;
  99. event->detail.key = tmpkey;
  100. }
  101. rg->currentDown = key;
  102. }
  103. else
  104. ErrorF("[xkb] InternalError! Illegal radio group %d\n", ndx);
  105. break;
  106. case XkbKB_Overlay1:
  107. case XkbKB_Overlay2:
  108. {
  109. unsigned which;
  110. if (behavior.type == XkbKB_Overlay1)
  111. which = XkbOverlay1Mask;
  112. else
  113. which = XkbOverlay2Mask;
  114. if ((xkbi->desc->ctrls->enabled_ctrls & which) == 0)
  115. break;
  116. if ((behavior.data >= xkbi->desc->min_key_code) &&
  117. (behavior.data <= xkbi->desc->max_key_code)) {
  118. event->detail.key = behavior.data;
  119. /* 9/11/94 (ef) -- XXX! need to match release with */
  120. /* press even if the state of the */
  121. /* corresponding overlay control */
  122. /* changes while the key is down */
  123. }
  124. }
  125. break;
  126. default:
  127. ErrorF("[xkb] unknown key behavior 0x%04x\n", behavior.type);
  128. break;
  129. }
  130. }
  131. XkbHandleActions(keybd, keybd, event);
  132. return;
  133. }
  134. void
  135. ProcessKeyboardEvent(InternalEvent *ev, DeviceIntPtr keybd)
  136. {
  137. KeyClassPtr keyc = keybd->key;
  138. XkbSrvInfoPtr xkbi = NULL;
  139. ProcessInputProc backup_proc;
  140. xkbDeviceInfoPtr xkb_priv = XKBDEVICEINFO(keybd);
  141. DeviceEvent *event = &ev->device_event;
  142. int is_press = (event->type == ET_KeyPress);
  143. int is_release = (event->type == ET_KeyRelease);
  144. /* We're only interested in key events. */
  145. if (!is_press && !is_release) {
  146. UNWRAP_PROCESS_INPUT_PROC(keybd, xkb_priv, backup_proc);
  147. keybd->public.processInputProc(ev, keybd);
  148. COND_WRAP_PROCESS_INPUT_PROC(keybd, xkb_priv, backup_proc,
  149. xkbUnwrapProc);
  150. return;
  151. }
  152. xkbi = keyc->xkbInfo;
  153. /* If AccessX filters are active, then pass it through to
  154. * AccessXFilter{Press,Release}Event; else, punt to
  155. * XkbProcessKeyboardEvent.
  156. *
  157. * If AXF[PK]E don't intercept anything (which they probably won't),
  158. * they'll punt through XPKE anyway. */
  159. if ((xkbi->desc->ctrls->enabled_ctrls & XkbAllFilteredEventsMask)) {
  160. if (is_press)
  161. AccessXFilterPressEvent(event, keybd);
  162. else if (is_release)
  163. AccessXFilterReleaseEvent(event, keybd);
  164. return;
  165. }
  166. else {
  167. XkbProcessKeyboardEvent(event, keybd);
  168. }
  169. return;
  170. }