1 /***********************************************************************
2  * ���٥�Ƚ��� (�����ƥ��¸)
3  *
4  *	�ܺ٤ϡ� event.h ����
5  ************************************************************************/
6 
7 #include <gdk/gdkkeysyms.h>
8 
9 #include "quasi88.h"
10 #include "getconf.h"
11 #include "keyboard.h"
12 
13 #include "event.h"
14 
15 
16 
17 int	gtksys_get_focus;		/* ���ߡ��ե����������꤫�ɤ���	*/
18 
19 
20 /*==========================================================================
21  * ��������ˤĤ���
22  *
23  *  �Ȥꤢ������106�����ܡ��ɷ���Ǥ��Ǻ���
24  *===========================================================================*/
25 
26 /* ���եȥ�����NumLock �������ݤΡ������Х���ǥ����ѹ��ơ��֥� */
27 
28 typedef struct {
29     int		type;		/* KEYCODE_INVALID / SYM / SCAN		*/
30     int		code;		/* ��������ܥ롢�ʤ����������������	*/
31     int		new_key88;	/* NumLock ON ���� QUASI88����������	*/
32     int		org_key88;	/* NumLock OFF���� QUASI88����������	*/
33 } T_BINDING;
34 
35 
36 /* �����Х���ǥ�����ǥե����(�����)�����ѹ�����ݤΡ��ơ��֥� */
37 
38 typedef struct {
39     int		type;		/* KEYCODE_INVALID / SYM / SCAN		*/
40     int		code;		/* ��������ܥ롢�ʤ����������������	*/
41     int		key88;		/* �ѹ����� QUASI88����������           */
42 } T_REMAPPING;
43 
44 
45 /* GDK �� keysym �� 0��511 ���ϰϤ˴ݤ�� */
46 
47 #define	LOCAL_KEYSYM(ks)						    \
48 	((((ks) & 0xff00) == 0xff00)			/* ��ǽ���� */	    \
49 		? (((ks) & 0x00ff) | 0x100)				    \
50 		: ((((ks) & 0xff00) == 0x0000)		/* ʸ������ */	    \
51 					? (ks) : 0))
52 
53 /*----------------------------------------------------------------------
54  * GDK �� keyval �� QUASI88 �� ���������ɤ��Ѵ�����ơ��֥�
55  *	ʸ������ �� ��ǽ���� �Υ�������ܥ�Τߡ�
56  *
57  *	��������ܥ� GDK_xxx �������줿�顢
58  *	keysym2key88[ GDK_xxx ] �������줿�Ȥ��롣
59  *
60  *	keysym2key88[] �ˤϡ� KEY88_xxx ���åȤ��Ƥ�����
61  *	����ͤ� keysym2key88_default[] ��Ʊ��
62  *----------------------------------------------------------------------*/
63 static int keysym2key88[ 256 + 256 ];
64 
65 
66 
67 /*----------------------------------------------------------------------
68  * ���եȥ����� NumLock ������� �����������Ѵ�����
69  *
70  *	binding[].code (GDK �� keyval) �������줿�顢
71  *	binding[].new_key88 (KEY88_xxx) �������줿���Ȥˤ��롣
72  *
73  *	���եȥ����� NumLock ������ϡ����ξ���ˤ������äơ�
74  *	keysym2key88[] �� keycode2key88[] ��������롣
75  *	�ѹ��Ǥ��륭���θĿ��ϡ�64�Ĥޤ� (�����������Ф�������)
76  *----------------------------------------------------------------------*/
77 static T_BINDING binding[ 64 ];
78 
79 
80 
81 
82 
83 /*----------------------------------------------------------------------
84  * GDK_xxx �� KEY88_xxx �Ѵ��ơ��֥� (�ǥե����)
85  *----------------------------------------------------------------------*/
86 
87 static const int keysym2key88_default[ 256 + 256 ] =
88 {
89   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
90   /* ʸ������						0x0000��0x00FF	*/
91   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
92 
93   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 
96   KEY88_SPACE,		/*	GDK_space               0x020	*/
97   KEY88_EXCLAM,		/*	GDK_exclam              0x021	*/
98   KEY88_QUOTEDBL,	/*	GDK_quotedbl            0x022	*/
99   KEY88_NUMBERSIGN,	/*	GDK_numbersign          0x023	*/
100   KEY88_DOLLAR,		/*	GDK_dollar              0x024	*/
101   KEY88_PERCENT,	/*	GDK_percent             0x025	*/
102   KEY88_AMPERSAND,	/*	GDK_ampersand           0x026	*/
103   KEY88_APOSTROPHE,	/*	GDK_apostrophe          0x027	*/
104   KEY88_PARENLEFT,	/*	GDK_parenleft           0x028	*/
105   KEY88_PARENRIGHT,	/*	GDK_parenright          0x029	*/
106   KEY88_ASTERISK,	/*	GDK_asterisk            0x02a	*/
107   KEY88_PLUS,		/*	GDK_plus                0x02b	*/
108   KEY88_COMMA,		/*	GDK_comma               0x02c	*/
109   KEY88_MINUS,		/*	GDK_minus               0x02d	*/
110   KEY88_PERIOD,		/*	GDK_period              0x02e	*/
111   KEY88_SLASH,		/*	GDK_slash               0x02f	*/
112 
113   KEY88_0,		/*	GDK_0                   0x030	*/
114   KEY88_1,		/*	GDK_1                   0x031	*/
115   KEY88_2,		/*	GDK_2                   0x032	*/
116   KEY88_3,		/*	GDK_3                   0x033	*/
117   KEY88_4,		/*	GDK_4                   0x034	*/
118   KEY88_5,		/*	GDK_5                   0x035	*/
119   KEY88_6,		/*	GDK_6                   0x036	*/
120   KEY88_7,		/*	GDK_7                   0x037	*/
121   KEY88_8,		/*	GDK_8                   0x038	*/
122   KEY88_9,		/*	GDK_9                   0x039	*/
123   KEY88_COLON,		/*	GDK_colon               0x03a	*/
124   KEY88_SEMICOLON,	/*	GDK_semicolon           0x03b	*/
125   KEY88_LESS,		/*	GDK_less                0x03c	*/
126   KEY88_EQUAL,		/*	GDK_equal               0x03d	*/
127   KEY88_GREATER,	/*	GDK_greater             0x03e	*/
128   KEY88_QUESTION,	/*	GDK_question            0x03f	*/
129 
130   KEY88_AT,		/*	GDK_at                  0x040	*/
131   KEY88_A,		/*	GDK_A                   0x041	*/
132   KEY88_B,		/*	GDK_B                   0x042	*/
133   KEY88_C,		/*	GDK_C                   0x043	*/
134   KEY88_D,		/*	GDK_D                   0x044	*/
135   KEY88_E,		/*	GDK_E                   0x045	*/
136   KEY88_F,		/*	GDK_F                   0x046	*/
137   KEY88_G,		/*	GDK_G                   0x047	*/
138   KEY88_H,		/*	GDK_H                   0x048	*/
139   KEY88_I,		/*	GDK_I                   0x049	*/
140   KEY88_J,		/*	GDK_J                   0x04a	*/
141   KEY88_K,		/*	GDK_K                   0x04b	*/
142   KEY88_L,		/*	GDK_L                   0x04c	*/
143   KEY88_M,		/*	GDK_M                   0x04d	*/
144   KEY88_N,		/*	GDK_N                   0x04e	*/
145   KEY88_O,		/*	GDK_O                   0x04f	*/
146 
147   KEY88_P,		/*	GDK_P                   0x050	*/
148   KEY88_Q,		/*	GDK_Q                   0x051	*/
149   KEY88_R,		/*	GDK_R                   0x052	*/
150   KEY88_S,		/*	GDK_S                   0x053	*/
151   KEY88_T,		/*	GDK_T                   0x054	*/
152   KEY88_U,		/*	GDK_U                   0x055	*/
153   KEY88_V,		/*	GDK_V                   0x056	*/
154   KEY88_W,		/*	GDK_W                   0x057	*/
155   KEY88_X,		/*	GDK_X                   0x058	*/
156   KEY88_Y,		/*	GDK_Y                   0x059	*/
157   KEY88_Z,		/*	GDK_Z                   0x05a	*/
158   KEY88_BRACKETLEFT,	/*	GDK_bracketleft         0x05b	*/
159   KEY88_YEN,		/*	GDK_backslash           0x05c	*/
160   KEY88_BRACKETRIGHT,	/*	GDK_bracketright        0x05d	*/
161   KEY88_CARET,		/*	GDK_asciicircum         0x05e	*/
162   KEY88_UNDERSCORE,	/*	GDK_underscore          0x05f	*/
163 
164   KEY88_BACKQUOTE,	/*	GDK_grave               0x060	*/
165   KEY88_a,		/*	GDK_a                   0x061	*/
166   KEY88_b,		/*	GDK_b                   0x062	*/
167   KEY88_c,		/*	GDK_c                   0x063	*/
168   KEY88_d,		/*	GDK_d                   0x064	*/
169   KEY88_e,		/*	GDK_e                   0x065	*/
170   KEY88_f,		/*	GDK_f                   0x066	*/
171   KEY88_g,		/*	GDK_g                   0x067	*/
172   KEY88_h,		/*	GDK_h                   0x068	*/
173   KEY88_i,		/*	GDK_i                   0x069	*/
174   KEY88_j,		/*	GDK_j                   0x06a	*/
175   KEY88_k,		/*	GDK_k                   0x06b	*/
176   KEY88_l,		/*	GDK_l                   0x06c	*/
177   KEY88_m,		/*	GDK_m                   0x06d	*/
178   KEY88_n,		/*	GDK_n                   0x06e	*/
179   KEY88_o,		/*	GDK_o                   0x06f	*/
180 
181   KEY88_p,		/*	GDK_p                   0x070	*/
182   KEY88_q,		/*	GDK_q                   0x071	*/
183   KEY88_r,		/*	GDK_r                   0x072	*/
184   KEY88_s,		/*	GDK_s                   0x073	*/
185   KEY88_t,		/*	GDK_t                   0x074	*/
186   KEY88_u,		/*	GDK_u                   0x075	*/
187   KEY88_v,		/*	GDK_v                   0x076	*/
188   KEY88_w,		/*	GDK_w                   0x077	*/
189   KEY88_x,		/*	GDK_x                   0x078	*/
190   KEY88_y,		/*	GDK_y                   0x079	*/
191   KEY88_z,		/*	GDK_z                   0x07a	*/
192   KEY88_BRACELEFT,	/*	GDK_braceleft           0x07b	*/
193   KEY88_BAR,		/*	GDK_bar                 0x07c	*/
194   KEY88_BRACERIGHT,	/*	GDK_braceright          0x07d	*/
195   KEY88_TILDE,		/*	GDK_asciitilde          0x07e	*/
196   0,
197 
198   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
199   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
200   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
202   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
203   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
206 
207 
208   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
209   /* ��ǽ����						0xFF00��0xFFFF	*/
210   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
211 
212   0, 0, 0, 0, 0, 0, 0, 0,
213   KEY88_BS,		/*	GDK_BackSpace		0xFF08	   */
214   KEY88_TAB,		/*	GDK_Tab			0xFF09	   */
215   KEY88_RETURN,		/*	GDK_Linefeed		0xFF0A	̵ */
216   KEY88_HOME,		/*	GDK_Clear		0xFF0B	̵ */
217   0,
218   KEY88_RETURNL,	/*	GDK_Return		0xFF0D	   */
219   0, 0,
220 
221   0, 0, 0,
222   KEY88_STOP,		/*	GDK_Pause		0xFF13	   */
223   KEY88_KANA,		/*	GDK_Scroll_Lock		0xFF14	   */
224   KEY88_COPY,		/*	GDK_Sys_Req		0xFF15	   */
225   0, 0,
226   0, 0, 0,
227   KEY88_ESC, 		/*	GDK_Escape		0xFF1B	   */
228   0, 0, 0, 0,
229 
230   0,			/*	GDK_Multi_key		0xFF20	̵ */
231   0,			/*	GDK_Kanji		0xFF21	   */
232   KEY88_KETTEI,		/*	GDK_Muhenkan		0xFF22	   */
233   KEY88_HENKAN,		/*	GDK_Henkan_Mode		0xFF23	   */
234   KEY88_KANA,		/*	GDK_Romaji		0xFF24     */
235   0,			/*	GDK_Hiragana		0xFF25  ̵ */
236   0,			/*	GDK_Katakana		0xFF26  ̵ */
237   KEY88_KANA,		/*	GDK_Hiragana_Katakana	0xFF27	   */
238   0,			/*	GDK_Zenkaku		0xFF28  ̵ */
239   0,			/*	GDK_Hankaku		0xFF29  ̵ */
240   KEY88_ZENKAKU,	/*	GDK_Zenkaku_Hankaku	0xFF2A	   */
241   0,			/*	GDK_Touroku		0xFF2B  ̵ */
242   0,			/*	GDK_Massyo		0xFF2C  ̵ */
243   KEY88_KANA,		/*	GDK_Kana_Lock		0xFF2D	̵ */
244   KEY88_KANA,		/*	GDK_Kana_Shift		0xFF2E  ̵ */
245   0,			/*	GDK_Eisu_Shift		0xFF2F  ̵ */
246 
247   KEY88_CAPS,		/*	GDK_Eisu_toggle		0xFF30     */
248   0, 0, 0, 0, 0, 0,
249   0,			/*	GDK_Kanji_Bangou	0xFF37  ̵ */
250   0, 0, 0, 0,
251   0,			/*	GDK_SingleCandidate	0xFF3C	̵ */
252   0,			/*	GDK_Zen_Koho		0xFF3D	̵ */
253   0,			/*	GDK_Mae_Koho		0xFF3E	̵ */
254   0,
255 
256   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
257 
258   KEY88_HOME,		/*	GDK_Home		0xFF50	   */
259   KEY88_LEFT,		/*	GDK_Left		0xFF51	   */
260   KEY88_UP,		/*	GDK_Up			0xFF52	   */
261   KEY88_RIGHT,		/*	GDK_Right		0xFF53	   */
262   KEY88_DOWN,		/*	GDK_Down		0xFF54	   */
263   KEY88_ROLLDOWN,	/*	GDK_Prior		0xFF55	   */
264   KEY88_ROLLUP,		/*	GDK_Next		0xFF56	   */
265   KEY88_HELP,		/*	GDK_End			0xFF57	   */
266   0,			/*	GDK_Begin		0xFF58	̵ */
267   0, 0, 0, 0, 0, 0, 0,
268 
269   0,			/*	GDK_Select		0xFF60	̵ */
270   KEY88_COPY,		/*	GDK_Print		0xFF61	   */
271   KEY88_COPY,		/*	GDK_Execute		0xFF62	   */
272   KEY88_INS, 		/*	GDK_Insert		0xFF63	   */
273   0,
274   0,			/*	GDK_Undo		0xFF65	̵ */
275   0,			/*	GDK_Redo		0xFF66	̵ */
276   0,			/*	GDK_Menu		0xFF67	   */
277   0,			/*	GDK_Find		0xFF68	̵ */
278   0,			/*	GDK_Cancel		0xFF69	̵ */
279   KEY88_HELP,		/*	GDK_Help		0xFF6A	̵ */
280   KEY88_STOP,		/*	GDK_Break		0xFF6B	   */
281   0, 0, 0, 0,
282 
283   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
284   KEY88_HENKAN,		/*	GDK_Mode_switch		0xFF7E	   */
285   0,			/*	GDK_Num_Lock		0xFF7F	   */
286 
287   KEY88_SPACE,		/*	GDK_KP_Space		0xFF80	̵ */
288   0, 0, 0, 0, 0, 0, 0, 0,
289   KEY88_TAB,		/*	GDK_KP_Tab		0xFF89	̵ */
290   0, 0, 0,
291   KEY88_RETURNR,	/*	GDK_KP_Enter		0xFF8D	   */
292   0, 0,
293 
294   0,
295   KEY88_F1,		/*	GDK_KP_F1		0xFF91	̵ */
296   KEY88_F2,		/*	GDK_KP_F2		0xFF92	̵ */
297   KEY88_F3,		/*	GDK_KP_F3		0xFF93	̵ */
298   KEY88_F4,		/*	GDK_KP_F4		0xFF94	̵ */
299   KEY88_KP_7,		/*	GDK_KP_Home		0xFF95	   */
300   KEY88_KP_4,		/*	GDK_KP_Left		0xFF96	   */
301   KEY88_KP_8,		/*	GDK_KP_Up		0xFF97	   */
302   KEY88_KP_6,		/*	GDK_KP_Right		0xFF98	   */
303   KEY88_KP_2,		/*	GDK_KP_Down		0xFF99	   */
304   KEY88_KP_9,		/*	GDK_KP_Page_Up		0xFF9A	   */
305   KEY88_KP_3,		/*	GDK_KP_Page_Down	0xFF9B	   */
306   KEY88_KP_1,		/*	GDK_KP_End		0xFF9C	   */
307   KEY88_KP_5,		/*	GDK_KP_Begin		0xFF9D	   */
308   KEY88_KP_0,		/*	GDK_KP_Insert		0xFF9E	   */
309   KEY88_KP_PERIOD,	/*	GDK_KP_Delete		0xFF9F	   */
310 
311   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
312   KEY88_KP_MULTIPLY,	/*	GDK_KP_Multiply		0xFFAA	   */
313   KEY88_KP_ADD,		/*	GDK_KP_Add		0xFFAB	   */
314   KEY88_KP_COMMA,	/*	GDK_KP_Separator	0xFFAC	̵ */
315   KEY88_KP_SUB,		/*	GDK_KP_Subtract		0xFFAD	   */
316   KEY88_KP_PERIOD,	/*	GDK_KP_Decimal		0xFFAE	   */
317   KEY88_KP_DIVIDE,	/*	GDK_KP_Divide		0xFFAF	   */
318 
319   KEY88_KP_0,		/*	GDK_KP_0		0xFFB0	   */
320   KEY88_KP_1,		/*	GDK_KP_1		0xFFB1	   */
321   KEY88_KP_2,		/*	GDK_KP_2		0xFFB2	   */
322   KEY88_KP_3,		/*	GDK_KP_3		0xFFB3	   */
323   KEY88_KP_4,		/*	GDK_KP_4		0xFFB4	   */
324   KEY88_KP_5,		/*	GDK_KP_5		0xFFB5	   */
325   KEY88_KP_6,		/*	GDK_KP_6		0xFFB6	   */
326   KEY88_KP_7,		/*	GDK_KP_7		0xFFB7	   */
327   KEY88_KP_8,		/*	GDK_KP_8		0xFFB8	   */
328   KEY88_KP_9,		/*	GDK_KP_9		0xFFB9	   */
329   0, 0, 0,
330   KEY88_KP_EQUAL,	/*	GDK_KP_Equal		0xFFBD	̵ */
331   KEY88_F1,		/*	GDK_F1			0xFFBE	   */
332   KEY88_F2,		/*	GDK_F2			0xFFBF	   */
333 
334   KEY88_F3,		/*	GDK_F3			0xFFC0	   */
335   KEY88_F4,		/*	GDK_F4			0xFFC1	   */
336   KEY88_F5,		/*	GDK_F5			0xFFC2	   */
337   KEY88_F6,		/*	GDK_F6			0xFFC3	   */
338   KEY88_F7,		/*	GDK_F7			0xFFC4	   */
339   KEY88_F8,		/*	GDK_F8			0xFFC5	   */
340   KEY88_F9,		/*	GDK_F9			0xFFC6	   */
341   KEY88_F10,		/*	GDK_F10			0xFFC7	   */
342   KEY88_F11,		/*	GDK_F11			0xFFC8	   */
343   KEY88_F12,		/*	GDK_F12			0xFFC9	   */
344   KEY88_F13,		/*	GDK_F13			0xFFCA	̵ */
345   KEY88_F14,		/*	GDK_F14			0xFFCB	̵ */
346   KEY88_F15,		/*	GDK_F15			0xFFCC	̵ */
347   KEY88_F16,		/*	GDK_F16			0xFFCD	̵ */
348   KEY88_F17,		/*	GDK_F17			0xFFCE	̵ */
349   KEY88_F18,		/*	GDK_F18			0xFFCF	̵ */
350 
351   KEY88_F19,		/*	GDK_F19			0xFFD0	̵ */
352   KEY88_F20,		/*	GDK_F20			0xFFD1	̵ */
353   0,			/*	GDK_F21			0xFFD2	̵ */
354   0,			/*	GDK_F22			0xFFD3	̵ */
355   0,			/*	GDK_F23			0xFFD4	̵ */
356   0,			/*	GDK_F24			0xFFD5	̵ */
357   0,			/*	GDK_F25			0xFFD6	̵ */
358   0,			/*	GDK_F26			0xFFD7	̵ */
359   0,			/*	GDK_F27			0xFFD8	̵ */
360   0,			/*	GDK_F28			0xFFD9	̵ */
361   0,			/*	GDK_F29			0xFFDA	̵ */
362   0,			/*	GDK_F30			0xFFDB	̵ */
363   0,			/*	GDK_F31			0xFFDC	̵ */
364   0,			/*	GDK_F32			0xFFDD	̵ */
365   0,			/*	GDK_F33			0xFFDE	̵ */
366   0,			/*	GDK_F34			0xFFDF	̵ */
367 
368   0,			/*	GDK_F35			0xFFE0	̵ */
369   KEY88_SHIFTL,		/*	GDK_Shift_L		0xFFE1	   */
370   KEY88_SHIFTR,		/*	GDK_Shift_R		0xFFE2	   */
371   KEY88_CTRL,		/*	GDK_Control_L		0xFFE3	   */
372   KEY88_CTRL,		/*	GDK_Control_R		0xFFE4	   */
373   KEY88_CAPS,		/*	GDK_Caps_Lock		0xFFE5	   */
374   KEY88_CAPS,		/*	GDK_Shift_Lock		0xFFE6	̵ */
375   KEY88_GRAPH,		/*	GDK_Meta_L		0xFFE7	   */
376   KEY88_GRAPH,		/*	GDK_Meta_R		0xFFE8	   */
377   KEY88_GRAPH,		/*	GDK_Alt_L		0xFFE9	   */
378   KEY88_GRAPH,		/*	GDK_Alt_R		0xFFEA	   */
379   0,			/*	GDK_Super_L		0xFFEB	   */
380   0,			/*	GDK_Super_R		0xFFEC	   */
381   0,			/*	GDK_Hyper_L		0xFFED	̵ */
382   0,			/*	GDK_Hyper_R		0xFFEE	̵ */
383   0,
384 
385   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
386   KEY88_DEL,		/*	GDK_Delete		0xFFFF	   */
387 
388 };
389 
390 
391 
392 /*----------------------------------------------------------------------
393  * ���եȥ����� NumLock ������� �����������Ѵ����� (�ǥե����)
394  *----------------------------------------------------------------------*/
395 
396 static const T_BINDING binding_default[] =
397 {
398     {	KEYCODE_SYM,	GDK_5,		KEY88_HOME,		0,	},
399     {	KEYCODE_SYM,	GDK_6,		KEY88_HELP,		0,	},
400     {	KEYCODE_SYM,	GDK_7,		KEY88_KP_7,		0,	},
401     {	KEYCODE_SYM,	GDK_8,		KEY88_KP_8,		0,	},
402     {	KEYCODE_SYM,	GDK_9,		KEY88_KP_9,		0,	},
403 /*  {	KEYCODE_SCAN,	?,		KEY88_KP_MULTIPLY,	0,	},*/
404     {	KEYCODE_SYM,	GDK_minus,	KEY88_KP_SUB,		0,	},
405     {	KEYCODE_SYM,	GDK_asciicircum,KEY88_KP_DIVIDE,	0,	},
406     {	KEYCODE_SYM,	GDK_u,		KEY88_KP_4,		0,	},
407     {	KEYCODE_SYM,	GDK_i,		KEY88_KP_5,		0,	},
408     {	KEYCODE_SYM,	GDK_o,		KEY88_KP_6,		0,	},
409     {	KEYCODE_SYM,	GDK_p,		KEY88_KP_ADD,		0,	},
410     {	KEYCODE_SYM,	GDK_j,		KEY88_KP_1,		0,	},
411     {	KEYCODE_SYM,	GDK_k,		KEY88_KP_2,		0,	},
412     {	KEYCODE_SYM,	GDK_l,		KEY88_KP_3,		0,	},
413     {	KEYCODE_SYM,	GDK_semicolon,	KEY88_KP_EQUAL,		0,	},
414     {	KEYCODE_SYM,	GDK_m,		KEY88_KP_0,		0,	},
415     {	KEYCODE_SYM,	GDK_comma,	KEY88_KP_COMMA,		0,	},
416     {	KEYCODE_SYM,	GDK_period,	KEY88_KP_PERIOD,	0,	},
417     {	KEYCODE_SYM,	GDK_slash,	KEY88_RETURNR,		0,	},
418 
419     {	KEYCODE_SYM,	GDK_percent,	KEY88_HOME,		0,	},
420     {	KEYCODE_SYM,	GDK_ampersand,	KEY88_HELP,		0,	},
421     {	KEYCODE_SYM,	GDK_apostrophe,	KEY88_KP_7,		0,	},
422     {	KEYCODE_SYM,	GDK_parenleft,	KEY88_KP_8,		0,	},
423     {	KEYCODE_SYM,	GDK_parenright,	KEY88_KP_9,		0,	},
424     {	KEYCODE_SYM,	GDK_equal,	KEY88_KP_SUB,		0,	},
425     {	KEYCODE_SYM,	GDK_asciitilde,	KEY88_KP_DIVIDE,	0,	},
426     {	KEYCODE_SYM,	GDK_U,		KEY88_KP_4,		0,	},
427     {	KEYCODE_SYM,	GDK_I,		KEY88_KP_5,		0,	},
428     {	KEYCODE_SYM,	GDK_O,		KEY88_KP_6,		0,	},
429     {	KEYCODE_SYM,	GDK_P,		KEY88_KP_ADD,		0,	},
430     {	KEYCODE_SYM,	GDK_J,		KEY88_KP_1,		0,	},
431     {	KEYCODE_SYM,	GDK_K,		KEY88_KP_2,		0,	},
432     {	KEYCODE_SYM,	GDK_L,		KEY88_KP_3,		0,	},
433     {	KEYCODE_SYM,	GDK_plus,	KEY88_KP_EQUAL,		0,	},
434     {	KEYCODE_SYM,	GDK_M,		KEY88_KP_0,		0,	},
435     {	KEYCODE_SYM,	GDK_less,	KEY88_KP_COMMA,		0,	},
436     {	KEYCODE_SYM,	GDK_greater,	KEY88_KP_PERIOD,	0,	},
437     {	KEYCODE_SYM,	GDK_question,	KEY88_RETURNR,		0,	},
438 
439     {	KEYCODE_INVALID,0,		0,			0,	},
440 };
441 
442 
443 
444 /******************************************************************************
445  * ���٥�ȥϥ�ɥ��
446  *
447  *	1/60��˸ƤӽФ���롣
448  *****************************************************************************/
449 
450 /*
451  * ����� ��ư����1������ƤФ��
452  */
event_init(void)453 void	event_init(void)
454 {
455     const T_REMAPPING *map;
456     const T_BINDING   *bin;
457     int i;
458 
459     /* �����ޥåԥ������ */
460 
461     memset(keysym2key88, 0, sizeof(keysym2key88));
462     memset(binding, 0, sizeof(binding));
463 
464     memcpy(keysym2key88,
465 	   keysym2key88_default, sizeof(keysym2key88_default));
466     memcpy(binding,
467 	   binding_default, sizeof(binding_default));
468 
469 
470     /* ���եȥ�����NumLock ���Υ��������ؤ��ν��� */
471 
472     for (i = 0; i < COUNTOF(binding); i++) {
473 
474 	if        (binding[i].type == KEYCODE_SYM) {
475 
476 	    binding[i].org_key88 = keysym2key88[LOCAL_KEYSYM(binding[i].code)];
477 
478 	} else {
479 	    break;
480 	}
481     }
482 
483 }
484 
485 
486 
487 /*
488  * �� 1/60 ��˸ƤФ��
489  */
event_update(void)490 void	event_update(void)
491 {
492 }
493 
494 /*
495  * ����� ��λ����1������ƤФ��
496  */
event_exit(void)497 void	event_exit(void)
498 {
499 }
500 
501 
502 
503 
504 /***********************************************************************
505  * ���ߤΥޥ�����ɸ�����ؿ�
506  *
507  ************************************************************************/
508 
event_get_mouse_pos(int * x,int * y)509 void	event_get_mouse_pos(int *x, int *y)
510 {
511 #if 0
512     gint xx, yy;
513 
514     gtk_widget_get_pointer(drawing_area, &xx, &yy);
515 
516     *x = xx;
517     *y = yy;
518 
519 #elif 0
520 
521     gint xx, yy;
522     GdkModifierType mask;
523 
524     gdk_window_get_pointer(drawing_area->window,
525 			   &xx, &yy, &mask);
526 
527     *x = xx;
528     *y = yy;
529 
530 #else
531 
532     *x = 0;
533     *y = 0;
534 
535 #endif
536 }
537 
538 
539 /******************************************************************************
540  * ���եȥ����� NumLock ͭ����̵��
541  *
542  *****************************************************************************/
543 
numlock_setup(int enable)544 static	void	numlock_setup(int enable)
545 {
546     int i;
547     int keysym;
548 
549     for (i = 0; i < COUNTOF(binding); i++) {
550 
551 	if        (binding[i].type == KEYCODE_SYM) {
552 
553 	    keysym = LOCAL_KEYSYM(binding[i].code);
554 
555 	    if (enable) {
556 		keysym2key88[ keysym ] = binding[i].new_key88;
557 	    } else {
558 		keysym2key88[ keysym ] = binding[i].org_key88;
559 	    }
560 
561 	} else {
562 	    break;
563 	}
564     }
565 }
566 
event_numlock_on(void)567 int	event_numlock_on (void){ numlock_setup(TRUE);  return TRUE; }
event_numlock_off(void)568 void	event_numlock_off(void){ numlock_setup(FALSE); }
569 
570 
571 
572 /******************************************************************************
573  * ���ߥ�졼�ȡ���˥塼���ݡ�������˥����⡼�� �� ���ϻ��ν���
574  *
575  *****************************************************************************/
576 
event_switch(void)577 void	event_switch(void)
578 {
579     if (quasi88_is_exec()) {		/*===================================*/
580 
581 	menubar_setup(TRUE);
582 
583     } else {
584 
585 	menubar_setup(FALSE);
586     }
587 }
588 
589 
590 
591 /******************************************************************************
592  * ���祤���ƥ��å�
593  *
594  *****************************************************************************/
595 
event_get_joystick_num(void)596 int	event_get_joystick_num(void)
597 {
598     return 0;
599 }
600 
601 
602 /*------------------------------------------------------------------------*/
603 
604 #define		ENABLE_MOTION_EVENT
605 
606 static gboolean destroy_event(GtkWidget *, gpointer);
607 static gboolean focusin_event(GtkWidget *, GdkEventFocus *, gpointer);
608 static gboolean focusout_event(GtkWidget *, GdkEventFocus *, gpointer);
609 static gboolean expose_event(GtkWidget *, GdkEventExpose *, gpointer);
610 static gboolean keypress_event(GtkWidget *, GdkEventKey *, gpointer);
611 static gboolean keyrelease_event(GtkWidget *, GdkEventKey *, gpointer);
612 static gboolean buttonpress_event(GtkWidget *, GdkEventButton *, gpointer);
613 static gboolean buttonrelease_event(GtkWidget *, GdkEventButton *, gpointer);
614 static gboolean motionnotify_event(GtkWidget *, GdkEventMotion *, gpointer);
615 
616 
617 /* �ᥤ������ɥ��Υ����ʥ������ */
gtksys_set_signal_frame(GtkWidget * widget)618 void	gtksys_set_signal_frame(GtkWidget *widget)
619 {
620     gtk_signal_connect(GTK_OBJECT(widget), "destroy",
621 		       GTK_SIGNAL_FUNC(destroy_event), NULL);
622 
623     gtk_signal_connect(GTK_OBJECT(widget), "focus_in_event",
624 		       GTK_SIGNAL_FUNC(focusin_event), NULL);
625 
626     gtk_signal_connect(GTK_OBJECT(widget), "focus_out_event",
627 		       GTK_SIGNAL_FUNC(focusout_event), NULL);
628 
629     gtk_signal_connect(GTK_OBJECT(widget), "key_press_event",
630 		       GTK_SIGNAL_FUNC(keypress_event), NULL);
631 
632     gtk_signal_connect(GTK_OBJECT(widget), "key_release_event",
633 		       GTK_SIGNAL_FUNC(keyrelease_event), NULL);
634 
635     gtk_widget_set_events(widget,
636 			  gtk_widget_get_events(widget) |
637 			  GDK_KEY_PRESS_MASK |
638 			  GDK_KEY_RELEASE_MASK);
639 }
640 
641 /* �ɥ��������ꥢ�Υ����ʥ������ */
gtksys_set_signal_view(GtkWidget * widget)642 void	gtksys_set_signal_view(GtkWidget *widget)
643 {
644     gtk_signal_connect(GTK_OBJECT(widget), "expose_event",
645 		       GTK_SIGNAL_FUNC(expose_event), NULL);
646 
647     gtk_signal_connect(GTK_OBJECT(widget), "button_press_event",
648 		       GTK_SIGNAL_FUNC(buttonpress_event), NULL);
649 
650     gtk_signal_connect(GTK_OBJECT(widget), "button_release_event",
651 		       GTK_SIGNAL_FUNC(buttonrelease_event), NULL);
652 
653 #ifdef	ENABLE_MOTION_EVENT
654     gtk_signal_connect(GTK_OBJECT(widget), "motion_notify_event",
655 		       GTK_SIGNAL_FUNC(motionnotify_event), NULL);
656 #endif
657 
658     gtk_widget_set_events(widget,
659 			  gtk_widget_get_events(widget) |
660 #ifdef	ENABLE_MOTION_EVENT
661 			  GDK_POINTER_MOTION_MASK |
662 #endif
663 			  GDK_EXPOSURE_MASK |
664 			  GDK_KEY_PRESS_MASK |
665 			  GDK_KEY_RELEASE_MASK |
666 			  GDK_BUTTON_PRESS_MASK |
667 			  GDK_BUTTON_RELEASE_MASK);
668 }
669 
670 
destroy_event(GtkWidget * widget,gpointer data)671 static gboolean destroy_event(GtkWidget *widget, gpointer data)
672 {
673     quasi88_quit();
674     return TRUE;		/* TRUE �� ���٥�Ƚ����Ϥ���ǽ���� */
675 				/* FALSE �� ���٥�Ȥ������Ť����� */
676 }
677 
focusin_event(GtkWidget * widget,GdkEventFocus * event,gpointer data)678 static gboolean focusin_event(GtkWidget *widget, GdkEventFocus *event,
679 			      gpointer data)
680 {
681     quasi88_focus_in();
682 
683     gtksys_get_focus = TRUE;
684     gtksys_set_attribute_focus_in();
685 
686     return TRUE;
687 }
688 
focusout_event(GtkWidget * widget,GdkEventFocus * event,gpointer data)689 static gboolean focusout_event(GtkWidget *widget, GdkEventFocus *event,
690 			       gpointer data)
691 {
692     quasi88_focus_out();
693 
694     gtksys_get_focus = FALSE;
695     gtksys_set_attribute_focus_out();
696 
697     return TRUE;
698 }
699 
expose_event(GtkWidget * widget,GdkEventExpose * event,gpointer data)700 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event,
701 			     gpointer data)
702 {
703     quasi88_expose();
704     return TRUE;
705 }
706 
key_event(guint keysym,int is_pressed)707 static void key_event(guint keysym, int is_pressed)
708 {
709     int    key88;
710 
711     if (quasi88_is_exec()) {
712 
713 	if ((keysym & 0xff00) == 0xff00) {		/* ��ǽ���� */
714 
715 	    key88 = keysym2key88[ (keysym & 0x00ff) | 0x100 ];
716 
717 	} else if ((keysym & 0xff00) == 0x0000) {	/* ʸ������ */
718 
719 	    key88 = keysym2key88[ (keysym) ];
720 
721 	} else if (keysym == GDK_ISO_Left_Tab) {	/* 0xFE20 */
722 
723 	    key88 = KEY88_TAB;
724 
725 	} else {					/* else... */
726 
727 	    key88 = 0;
728 
729 	}
730 
731     } else {
732 
733 	if ((keysym & 0xff00) == 0xff00) {		/* ��ǽ���� */
734 
735 	    key88 = keysym2key88[ (keysym & 0x00ff) | 0x100 ];
736 
737 	} else if ((keysym & 0xff00) == 0x0000) {	/* ʸ������ */
738 
739 	    key88 = keysym;
740 
741 	} else if (keysym == GDK_ISO_Left_Tab) {	/* 0xFE20 */
742 
743 	    key88 = KEY88_TAB;
744 
745 	} else {					/* else... */
746 
747 	    key88 = 0;
748 
749 	}
750 
751     }
752 
753     if (key88) {
754 	quasi88_key(key88, (is_pressed));
755     }
756 }
757 
keypress_event(GtkWidget * widget,GdkEventKey * event,gpointer data)758 static gboolean keypress_event(GtkWidget *widget, GdkEventKey *event,
759 			       gpointer data)
760 {
761     key_event(event->keyval, TRUE);
762     return FALSE;
763 }
764 
keyrelease_event(GtkWidget * widget,GdkEventKey * event,gpointer data)765 static gboolean keyrelease_event(GtkWidget *widget, GdkEventKey *event,
766 				 gpointer data)
767 {
768     key_event(event->keyval, FALSE);
769     return FALSE;
770 }
771 
button_event(guint button,int x,int y,int is_pressed)772 static void button_event(guint button, int x, int y, int is_pressed)
773 {
774     int key88;
775 
776     if      (button == 1) key88 = KEY88_MOUSE_L;
777     else if (button == 3) key88 = KEY88_MOUSE_R;
778     else                  key88 = 0;
779 
780     if (key88) {
781 #ifndef	ENABLE_MOTION_EVENT
782 	quasi88_mouse_moved_abs(x, y);
783 #endif
784 	quasi88_mouse(key88, (is_pressed));
785     }
786 }
buttonpress_event(GtkWidget * widget,GdkEventButton * event,gpointer data)787 static gboolean buttonpress_event(GtkWidget *widget, GdkEventButton *event,
788 				  gpointer data)
789 {
790     button_event(event->button, (int)event->x, (int)event->y, TRUE);
791     return FALSE;
792 }
793 
buttonrelease_event(GtkWidget * widget,GdkEventButton * event,gpointer data)794 static gboolean buttonrelease_event(GtkWidget *widget, GdkEventButton *event,
795 				    gpointer data)
796 {
797     button_event(event->button, (int)event->x, (int)event->y, FALSE);
798     return FALSE;
799 }
800 
801 #ifdef	ENABLE_MOTION_EVENT
motionnotify_event(GtkWidget * widget,GdkEventMotion * event,gpointer data)802 static gboolean motionnotify_event(GtkWidget *widget, GdkEventMotion *event,
803 				   gpointer data)
804 {
805     int x, y;
806 
807     x = (int)(event->x);
808     y = (int)(event->y);
809 
810     quasi88_mouse_moved_abs(x, y);
811 
812     return FALSE;
813 }
814 #endif
815