key.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*****************************************************************************/
  2. /* ここから */
  3. /*****************************************************************************/
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "wonx_include/key.h"
  7. #include "WonX.h"
  8. /*****************************************************************************/
  9. /* 互換関数の定義 */
  10. /*****************************************************************************/
  11. /*
  12. * Xサーバとの同期の整合性がとれなくなるなどの問題が考えられるので,
  13. * 互換関数の内部は UNIXTimer_Pause(), UNIXTimer_Unpause() でくくり,
  14. * タイマ割り込みを一時停止して処理を行う.また,unpause するまえに,
  15. * かならず sync するようにする.
  16. */
  17. /*
  18. * タイマの一時停止の2重解除の問題が出てくるので,
  19. * 互換関数から互換関数を呼んではいけない.
  20. * (一時停止はネストされるが,いちおう)
  21. * 似たような処理をする関数の場合は,必ず static な別関数に処理をまとめ,
  22. * そっちを呼び出すようにすること.
  23. * 引数の表示の問題もあるしね.
  24. */
  25. int key_press_check(void)
  26. {
  27. XDisplay x_display;
  28. int ret;
  29. if (!WonX_IsCreated()) WonX_Create();
  30. /* タイマを一時停止する */
  31. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  32. printf("call : key_press_check() : "); fflush(stdout);
  33. x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
  34. XDisplay_Sync(x_display);
  35. ret = XDisplay_GetKeyPress(x_display);
  36. WonXDisplay_Sync(WonX_GetWonXDisplay());
  37. printf("call : key_press_check() : return value = 0x%04x\n", (int)ret);
  38. fflush(stdout);
  39. /* タイマをもとに戻す */
  40. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  41. return (ret);
  42. }
  43. int key_hit_check(void)
  44. {
  45. XDisplay x_display;
  46. int ret;
  47. if (!WonX_IsCreated()) WonX_Create();
  48. /* タイマを一時停止する */
  49. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  50. printf("call : key_hit_check() : "); fflush(stdout);
  51. x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
  52. XDisplay_Sync(x_display);
  53. ret = XDisplay_GetKeyPress(x_display);
  54. WonXDisplay_Sync(WonX_GetWonXDisplay());
  55. printf("call : key_hit_check() : return value = 0x%04x\n", (int)ret);
  56. fflush(stdout);
  57. /* タイマをもとに戻す */
  58. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  59. return (ret);
  60. }
  61. int key_wait(void)
  62. {
  63. XDisplay x_display;
  64. int ret;
  65. if (!WonX_IsCreated()) WonX_Create();
  66. /* タイマを一時停止する */
  67. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  68. printf("call : key_wait() : "); fflush(stdout);
  69. x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
  70. /*
  71. * 以下はホットスポットになり得るので注意!
  72. */
  73. ret = 0;
  74. do {
  75. XDisplay_Sync(x_display);
  76. ret = XDisplay_GetKeyPress(x_display);
  77. } while (ret == 0);
  78. WonXDisplay_Sync(WonX_GetWonXDisplay());
  79. printf("call : key_wait() : return value = 0x%04x\n", (int)ret);
  80. fflush(stdout);
  81. /* タイマをもとに戻す */
  82. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  83. return (ret);
  84. }
  85. void key_set_repeat(int rate, int delay)
  86. {
  87. if (!WonX_IsCreated()) WonX_Create();
  88. /* タイマを一時停止する */
  89. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  90. printf("call : key_set_repeat() : rate = %d, delay = %d, ", rate, delay);
  91. fflush(stdout);
  92. WonXDisplay_Sync(WonX_GetWonXDisplay());
  93. printf("call : key_set_repeat() : return value = none\n"); fflush(stdout);
  94. /* タイマをもとに戻す */
  95. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  96. return;
  97. }
  98. int key_get_repeat(void)
  99. {
  100. int ret;
  101. if (!WonX_IsCreated()) WonX_Create();
  102. /* タイマを一時停止する */
  103. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  104. printf("call : key_get_repeat() : "); fflush(stdout);
  105. ret = 0;
  106. WonXDisplay_Sync(WonX_GetWonXDisplay());
  107. printf("call : key_get_repeat() : return value = 0x%04x\n", (int)ret);
  108. fflush(stdout);
  109. /* タイマをもとに戻す */
  110. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  111. return (ret);
  112. }
  113. int key_hit_check_with_repeat(void)
  114. {
  115. XDisplay x_display;
  116. int ret;
  117. if (!WonX_IsCreated()) WonX_Create();
  118. /* タイマを一時停止する */
  119. UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  120. printf("call : key_hit_check_with_repeat() : "); fflush(stdout);
  121. x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
  122. XDisplay_Sync(x_display);
  123. ret = XDisplay_GetKeyPress(x_display);
  124. WonXDisplay_Sync(WonX_GetWonXDisplay());
  125. printf("call : key_hit_check_with_repeat() : return value = 0x%04x\n",
  126. (int)ret);
  127. fflush(stdout);
  128. /* タイマをもとに戻す */
  129. UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
  130. return (ret);
  131. }
  132. /*****************************************************************************/
  133. /* ここまで */
  134. /*****************************************************************************/
  135. /*****************************************************************************/
  136. /* End of File. */
  137. /*****************************************************************************/