123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- /*****************************************************************************/
- /* ここから */
- /*****************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include "wonx_include/key.h"
- #include "WonX.h"
- /*****************************************************************************/
- /* 互換関数の定義 */
- /*****************************************************************************/
- /*
- * Xサーバとの同期の整合性がとれなくなるなどの問題が考えられるので,
- * 互換関数の内部は UNIXTimer_Pause(), UNIXTimer_Unpause() でくくり,
- * タイマ割り込みを一時停止して処理を行う.また,unpause するまえに,
- * かならず sync するようにする.
- */
- /*
- * タイマの一時停止の2重解除の問題が出てくるので,
- * 互換関数から互換関数を呼んではいけない.
- * (一時停止はネストされるが,いちおう)
- * 似たような処理をする関数の場合は,必ず static な別関数に処理をまとめ,
- * そっちを呼び出すようにすること.
- * 引数の表示の問題もあるしね.
- */
- int key_press_check(void)
- {
- XDisplay x_display;
- int ret;
- if (!WonX_IsCreated()) WonX_Create();
- /* タイマを一時停止する */
- UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- printf("call : key_press_check() : \n"); fflush(stdout);
- x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
- XDisplay_Sync(x_display);
- ret = XDisplay_GetKeyPress(x_display);
- WonXDisplay_Sync(WonX_GetWonXDisplay());
- printf("call : key_press_check() : return value = 0x%04x\n", (int)ret);
- fflush(stdout);
- /* タイマをもとに戻す */
- UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- return (ret);
- }
- int key_hit_check(void)
- {
- XDisplay x_display;
- int ret;
- if (!WonX_IsCreated()) WonX_Create();
- /* タイマを一時停止する */
- UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- printf("call : key_hit_check() : \n"); fflush(stdout);
- x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
- XDisplay_Sync(x_display);
- ret = XDisplay_GetKeyPress(x_display);
- WonXDisplay_Sync(WonX_GetWonXDisplay());
- printf("call : key_hit_check() : return value = 0x%04x\n", (int)ret);
- fflush(stdout);
- /* タイマをもとに戻す */
- UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- return (ret);
- }
- int key_wait(void)
- {
- XDisplay x_display;
- int ret;
- if (!WonX_IsCreated()) WonX_Create();
- /* タイマを一時停止する */
- UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- printf("call : key_wait() : \n"); fflush(stdout);
- x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
- /*
- * 以下はホットスポットになり得るので注意!
- */
- ret = 0;
- do {
- XDisplay_Sync(x_display);
- ret = XDisplay_GetKeyPress(x_display);
- } while (ret == 0);
- WonXDisplay_Sync(WonX_GetWonXDisplay());
- printf("call : key_wait() : return value = 0x%04x\n", (int)ret);
- fflush(stdout);
- /* タイマをもとに戻す */
- UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- return (ret);
- }
- void key_set_repeat(int rate, int delay)
- {
- if (!WonX_IsCreated()) WonX_Create();
- /* タイマを一時停止する */
- UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- printf("call : key_set_repeat() : rate = %d, delay = %d\n", rate, delay);
- fflush(stdout);
- WonXDisplay_Sync(WonX_GetWonXDisplay());
- printf("call : key_set_repeat() : return value = none\n"); fflush(stdout);
- /* タイマをもとに戻す */
- UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- return;
- }
- int key_get_repeat(void)
- {
- int ret;
- if (!WonX_IsCreated()) WonX_Create();
- /* タイマを一時停止する */
- UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- printf("call : key_get_repeat() : \n"); fflush(stdout);
- ret = 0;
- WonXDisplay_Sync(WonX_GetWonXDisplay());
- printf("call : key_get_repeat() : return value = 0x%04x\n", (int)ret);
- fflush(stdout);
- /* タイマをもとに戻す */
- UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- return (ret);
- }
- int key_hit_check_with_repeat(void)
- {
- XDisplay x_display;
- int ret;
- if (!WonX_IsCreated()) WonX_Create();
- /* タイマを一時停止する */
- UNIXTimer_Pause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- printf("call : key_hit_check_with_repeat() : \n"); fflush(stdout);
- x_display = WonXDisplay_GetXDisplay(WonX_GetWonXDisplay());
- XDisplay_Sync(x_display);
- ret = XDisplay_GetKeyPress(x_display);
- WonXDisplay_Sync(WonX_GetWonXDisplay());
- printf("call : key_hit_check_with_repeat() : return value = 0x%04x\n",
- (int)ret);
- fflush(stdout);
- /* タイマをもとに戻す */
- UNIXTimer_Unpause(WonXSystem_GetUNIXTimer(WonX_GetWonXSystem()));
- return (ret);
- }
- /*****************************************************************************/
- /* ここまで */
- /*****************************************************************************/
- /*****************************************************************************/
- /* End of File. */
- /*****************************************************************************/
|