usim

Check-in [401803fc1b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:sdl2.c: Include <X11/keysym.h> and <X11/X.h>.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ams/sdl
Files: files | file ages | folders
SHA3-256: 401803fc1b92145162b1d0c00c3c099fac65ddab142610c336ac0eda957579c4
User & Date: ams 2024-06-18 07:02:53
Context
2024-06-18
07:24
sdl2.c: Half working buckies. check-in: 0c7ac5fa5d user: ams tags: ams/sdl
07:02
sdl2.c: Include <X11/keysym.h> and <X11/X.h>. check-in: 401803fc1b user: ams tags: ams/sdl
2024-06-17
13:58
Meh .. X11 / SDL2 stuff. check-in: 9835eb47e1 user: ams tags: ams/sdl
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to sdl2.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* sdl2.c --- SDL2 routines used by the TV and KBD interfaces
 */

#include <signal.h>

#include <SDL.h>

#include "tv.h"
#include "kbd.h"
#include "mouse.h"
#include "utrace.h"
#include "idle.h"

#define ShiftMapIndex		0
#define LockMapIndex		1
#define ControlMapIndex		2
#define Mod1MapIndex		3
#define Mod2MapIndex		4
#define Mod3MapIndex		5
#define Mod4MapIndex		6
#define Mod5MapIndex		7


#define XK_0                             0x0030  /* U+0030 DIGIT ZERO */
#define XK_1                             0x0031  /* U+0031 DIGIT ONE */
#define XK_2                             0x0032  /* U+0032 DIGIT TWO */
#define XK_3                             0x0033  /* U+0033 DIGIT THREE */
#define XK_4                             0x0034  /* U+0034 DIGIT FOUR */
#define XK_5                             0x0035  /* U+0035 DIGIT FIVE */
#define XK_6                             0x0036  /* U+0036 DIGIT SIX */
#define XK_7                             0x0037  /* U+0037 DIGIT SEVEN */
#define XK_8                             0x0038  /* U+0038 DIGIT EIGHT */
#define XK_9                             0x0039  /* U+0039 DIGIT NINE */
#define XK_A                             0x0041  /* U+0041 LATIN CAPITAL LETTER A */
#define XK_B                             0x0042  /* U+0042 LATIN CAPITAL LETTER B */
#define XK_BackSpace                     0xff08  /* U+0008 BACKSPACE */
#define XK_C                             0x0043  /* U+0043 LATIN CAPITAL LETTER C */
#define XK_D                             0x0044  /* U+0044 LATIN CAPITAL LETTER D */
#define XK_Down                          0xff54  /* Move down, down arrow */
#define XK_E                             0x0045  /* U+0045 LATIN CAPITAL LETTER E */
#define XK_End                           0xff57  /* EOL */
#define XK_Escape                        0xff1b  /* U+001B ESCAPE */
#define XK_F                             0x0046  /* U+0046 LATIN CAPITAL LETTER F */
#define XK_F1                            0xffbe
#define XK_F2                            0xffbf
#define XK_F3                            0xffc0
#define XK_F4                            0xffc1
#define XK_F5                            0xffc2
#define XK_F6                            0xffc3
#define XK_F7                            0xffc4
#define XK_G                             0x0047  /* U+0047 LATIN CAPITAL LETTER G */
#define XK_H                             0x0048  /* U+0048 LATIN CAPITAL LETTER H */
#define XK_Home                          0xff50
#define XK_I                             0x0049  /* U+0049 LATIN CAPITAL LETTER I */
#define XK_J                             0x004a  /* U+004A LATIN CAPITAL LETTER J */
#define XK_K                             0x004b  /* U+004B LATIN CAPITAL LETTER K */
#define XK_L                             0x004c  /* U+004C LATIN CAPITAL LETTER L */
#define XK_Left                          0xff51  /* Move left, left arrow */
#define XK_M                             0x004d  /* U+004D LATIN CAPITAL LETTER M */
#define XK_N                             0x004e  /* U+004E LATIN CAPITAL LETTER N */
#define XK_O                             0x004f  /* U+004F LATIN CAPITAL LETTER O */
#define XK_P                             0x0050  /* U+0050 LATIN CAPITAL LETTER P */
#define XK_Page_Down                     0xff56  /* deprecated alias for Next */
#define XK_Page_Up                       0xff55  /* deprecated alias for Prior */
#define XK_Q                             0x0051  /* U+0051 LATIN CAPITAL LETTER Q */
#define XK_R                             0x0052  /* U+0052 LATIN CAPITAL LETTER R */
#define XK_Return                        0xff0d  /* U+000D CARRIAGE RETURN */
#define XK_Right                         0xff53  /* Move right, right arrow */
#define XK_S                             0x0053  /* U+0053 LATIN CAPITAL LETTER S */
#define XK_T                             0x0054  /* U+0054 LATIN CAPITAL LETTER T */
#define XK_Tab                           0xff09  /* U+0009 CHARACTER TABULATION */
#define XK_U                             0x0055  /* U+0055 LATIN CAPITAL LETTER U */
#define XK_Up                            0xff52  /* Move up, up arrow */
#define XK_V                             0x0056  /* U+0056 LATIN CAPITAL LETTER V */
#define XK_W                             0x0057  /* U+0057 LATIN CAPITAL LETTER W */
#define XK_X                             0x0058  /* U+0058 LATIN CAPITAL LETTER X */
#define XK_Y                             0x0059  /* U+0059 LATIN CAPITAL LETTER Y */
#define XK_Z                             0x005a  /* U+005A LATIN CAPITAL LETTER Z */
#define XK_a                             0x0061  /* U+0061 LATIN SMALL LETTER A */
#define XK_apostrophe                    0x0027  /* U+0027 APOSTROPHE */
#define XK_b                             0x0062  /* U+0062 LATIN SMALL LETTER B */
#define XK_backslash                     0x005c  /* U+005C REVERSE SOLIDUS */
#define XK_bracketleft                   0x005b  /* U+005B LEFT SQUARE BRACKET */
#define XK_bracketright                  0x005d  /* U+005D RIGHT SQUARE BRACKET */
#define XK_c                             0x0063  /* U+0063 LATIN SMALL LETTER C */
#define XK_comma                         0x002c  /* U+002C COMMA */
#define XK_d                             0x0064  /* U+0064 LATIN SMALL LETTER D */
#define XK_e                             0x0065  /* U+0065 LATIN SMALL LETTER E */
#define XK_equal                         0x003d  /* U+003D EQUALS SIGN */
#define XK_f                             0x0066  /* U+0066 LATIN SMALL LETTER F */
#define XK_g                             0x0067  /* U+0067 LATIN SMALL LETTER G */
#define XK_grave                         0x0060  /* U+0060 GRAVE ACCENT */
#define XK_h                             0x0068  /* U+0068 LATIN SMALL LETTER H */
#define XK_i                             0x0069  /* U+0069 LATIN SMALL LETTER I */
#define XK_j                             0x006a  /* U+006A LATIN SMALL LETTER J */
#define XK_k                             0x006b  /* U+006B LATIN SMALL LETTER K */
#define XK_l                             0x006c  /* U+006C LATIN SMALL LETTER L */
#define XK_m                             0x006d  /* U+006D LATIN SMALL LETTER M */
#define XK_minus                         0x002d  /* U+002D HYPHEN-MINUS */
#define XK_n                             0x006e  /* U+006E LATIN SMALL LETTER N */
#define XK_o                             0x006f  /* U+006F LATIN SMALL LETTER O */
#define XK_p                             0x0070  /* U+0070 LATIN SMALL LETTER P */
#define XK_period                        0x002e  /* U+002E FULL STOP */
#define XK_q                             0x0071  /* U+0071 LATIN SMALL LETTER Q */
#define XK_r                             0x0072  /* U+0072 LATIN SMALL LETTER R */
#define XK_s                             0x0073  /* U+0073 LATIN SMALL LETTER S */
#define XK_semicolon                     0x003b  /* U+003B SEMICOLON */
#define XK_slash                         0x002f  /* U+002F SOLIDUS */
#define XK_space                 0x0020  // U+0020 SPACE
#define XK_t                             0x0074  /* U+0074 LATIN SMALL LETTER T */
#define XK_u                             0x0075  /* U+0075 LATIN SMALL LETTER U */
#define XK_v                             0x0076  /* U+0076 LATIN SMALL LETTER V */
#define XK_w                             0x0077  /* U+0077 LATIN SMALL LETTER W */
#define XK_x                             0x0078  /* U+0078 LATIN SMALL LETTER X */
#define XK_y                             0x0079  /* U+0079 LATIN SMALL LETTER Y */
#define XK_z                             0x007a  /* U+007A LATIN SMALL LETTER Z */
#define XK_0                             0x0030  /* U+0030 DIGIT ZERO */
#define XK_1                             0x0031  /* U+0031 DIGIT ONE */
#define XK_2                             0x0032  /* U+0032 DIGIT TWO */
#define XK_3                             0x0033  /* U+0033 DIGIT THREE */
#define XK_4                             0x0034  /* U+0034 DIGIT FOUR */
#define XK_5                             0x0035  /* U+0035 DIGIT FIVE */
#define XK_6                             0x0036  /* U+0036 DIGIT SIX */
#define XK_7                             0x0037  /* U+0037 DIGIT SEVEN */
#define XK_8                             0x0038  /* U+0038 DIGIT EIGHT */
#define XK_9                             0x0039  /* U+0039 DIGIT NINE */
#define XK_minus                         0x002d  /* U+002D HYPHEN-MINUS */
#define XK_underscore                    0x005f  /* U+005F LOW LINE */
#define XK_equal                         0x003d  /* U+003D EQUALS SIGN */
#define XK_plus                          0x002b  /* U+002B PLUS SIGN */
#define XK_exclam                        0x0021  /* U+0021 EXCLAMATION MARK */
#define XK_numbersign                    0x0023  /* U+0023 NUMBER SIGN */
#define XK_dollar                        0x0024  /* U+0024 DOLLAR SIGN */
#define XK_percent                       0x0025  /* U+0025 PERCENT SIGN */
#define XK_asciicircum                   0x005e  /* U+005E CIRCUMFLEX ACCENT */
#define XK_ampersand                     0x0026  /* U+0026 AMPERSAND */
#define XK_asterisk                      0x002a  /* U+002A ASTERISK */
#define XK_parenleft                     0x0028  /* U+0028 LEFT PARENTHESIS */
#define XK_parenright                    0x0029  /* U+0029 RIGHT PARENTHESIS */
#define XK_at                            0x0040  /* U+0040 COMMERCIAL AT */
#define XK_asciitilde                    0x007e  /* U+007E TILDE */
#define XK_Tab                           0xff09  /* U+0009 CHARACTER TABULATION */
#define XK_braceleft                     0x007b  /* U+007B LEFT CURLY BRACKET */
#define XK_braceright                    0x007d  /* U+007D RIGHT CURLY BRACKET */
#define XK_bracketleft                   0x005b  /* U+005B LEFT SQUARE BRACKET */
#define XK_bracketright                  0x005d  /* U+005D RIGHT SQUARE BRACKET */
#define XK_bar                           0x007c  /* U+007C VERTICAL LINE */
#define XK_BackSpace                     0xff08  /* U+0008 BACKSPACE */
#define XK_semicolon                     0x003b  /* U+003B SEMICOLON */
#define XK_apostrophe                    0x0027  /* U+0027 APOSTROPHE */
#define XK_Return                        0xff0d  /* U+000D CARRIAGE RETURN */
#define XK_colon                         0x003a  /* U+003A COLON */
#define XK_apostrophe                    0x0027  /* U+0027 APOSTROPHE */
#define XK_quotedbl                      0x0022  /* U+0022 QUOTATION MARK */
#define XK_less                          0x003c  /* U+003C LESS-THAN SIGN */
#define XK_greater                       0x003e  /* U+003E GREATER-THAN SIGN */
#define XK_question                      0x003f  /* U+003F QUESTION MARK */


SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;

/*
 * This is shared between x11.c, and sdl2.c ... the only difference is













<
<
<
<
<
<
<
<
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6
7
8
9
10
11
12
13








14
15







































































































































16
17
18
19
20
21
22
/* sdl2.c --- SDL2 routines used by the TV and KBD interfaces
 */

#include <signal.h>

#include <SDL.h>

#include "tv.h"
#include "kbd.h"
#include "mouse.h"
#include "utrace.h"
#include "idle.h"









#include <X11/keysym.h> // for XK_FOO  meh
#include <X11/X.h> // for FOOMapIndex  meh








































































































































SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *texture;

/*
 * This is shared between x11.c, and sdl2.c ... the only difference is
205
206
207
208
209
210
211
212
213


214
215
216
217
218
219
220
//	u_minh = 0x7fffffff;
//	u_maxh = 0;
//	u_minv = 0x7fffffff;
//	u_maxv = 0;
}

int
sdl2_bucky(SDL_Keymod mod)
{


	if (mod & KMOD_CTRL) return ControlMapIndex;
	if (mod & KMOD_SHIFT) return ShiftMapIndex;
	if (mod & KMOD_ALT) return Mod1MapIndex;
	if (mod & KMOD_NUM) return Mod2MapIndex;
	if (mod & KMOD_MODE) return Mod3MapIndex;
	if (mod & KMOD_GUI) return Mod4MapIndex;
	if (mod & KMOD_SCROLL) return Mod5MapIndex;







|

>
>







62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//	u_minh = 0x7fffffff;
//	u_maxh = 0;
//	u_minv = 0x7fffffff;
//	u_maxv = 0;
}

int
sdl2_bucky(/* SDL_Keymod mod */)
{
		int mod = SDL_GetModState();

	if (mod & KMOD_CTRL) return ControlMapIndex;
	if (mod & KMOD_SHIFT) return ShiftMapIndex;
	if (mod & KMOD_ALT) return Mod1MapIndex;
	if (mod & KMOD_NUM) return Mod2MapIndex;
	if (mod & KMOD_MODE) return Mod3MapIndex;
	if (mod & KMOD_GUI) return Mod4MapIndex;
	if (mod & KMOD_SCROLL) return Mod5MapIndex;
289
290
291
292
293
294
295

















296
297
298
299
300
301
302
303
304
305
306
307
308
309
310



311
312
313
314
315
316
317
318
	case SDL_SCANCODE_N: return e.keysym.mod & KMOD_SHIFT ? XK_N : XK_n;
	case SDL_SCANCODE_M: return e.keysym.mod & KMOD_SHIFT ? XK_M : XK_m;
	case SDL_SCANCODE_COMMA: return e.keysym.mod & KMOD_SHIFT ? XK_less : XK_comma;
	case SDL_SCANCODE_PERIOD: return e.keysym.mod & KMOD_SHIFT ? XK_greater : XK_period;
	case SDL_SCANCODE_SLASH: return e.keysym.mod & KMOD_SHIFT ? XK_question : XK_slash;
	case SDL_SCANCODE_SPACE: return XK_space;


















	default: return 0xffffff;
	}
}

static void
process_key(SDL_KeyboardEvent e, int keydown)
{
//	KeySym keysym;
//	SDLKey keycode;

	int bi;
	int keysym;

	idle_keyboard_activity();
	keysym = sdl2_keysym_to_xk(e);




	if (kbd_type == 0) {
		if (!keydown)
			return;
		bi = 0;
		int mod = SDL_GetModState();
		if (mod & KMOD_SHIFT)
			knight_process_bucky(ShiftMapIndex, &bi);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|














>
>
>
|







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
	case SDL_SCANCODE_N: return e.keysym.mod & KMOD_SHIFT ? XK_N : XK_n;
	case SDL_SCANCODE_M: return e.keysym.mod & KMOD_SHIFT ? XK_M : XK_m;
	case SDL_SCANCODE_COMMA: return e.keysym.mod & KMOD_SHIFT ? XK_less : XK_comma;
	case SDL_SCANCODE_PERIOD: return e.keysym.mod & KMOD_SHIFT ? XK_greater : XK_period;
	case SDL_SCANCODE_SLASH: return e.keysym.mod & KMOD_SHIFT ? XK_question : XK_slash;
	case SDL_SCANCODE_SPACE: return XK_space;

// case SDL_SCANCODE_MODE: return ???;
	case SDL_SCANCODE_LSHIFT: return XK_Shift_L;
	case SDL_SCANCODE_RSHIFT: return XK_Shift_R;
	case SDL_SCANCODE_LCTRL: return XK_Control_L;
	case SDL_SCANCODE_RCTRL: return XK_Control_R;
	case SDL_SCANCODE_CAPSLOCK: return XK_Caps_Lock;
// case ???: return XK_Shift_Lock;
		
	case SDL_SCANCODE_LGUI: return XK_Meta_L;
	case SDL_SCANCODE_RGUI: return XK_Meta_R;
	case SDL_SCANCODE_LALT: return XK_Alt_L;
	case SDL_SCANCODE_RALT: return XK_Alt_R;
// case ???: return XK_Super_L;
// case ???: return XK_Super_R;
// case ???: return XK_Hyper_L;
// case ???: return XK_Hyper_R;

	default: return XK_VoidSymbol;
	}
}

static void
process_key(SDL_KeyboardEvent e, int keydown)
{
//	KeySym keysym;
//	SDLKey keycode;

	int bi;
	int keysym;

	idle_keyboard_activity();
	keysym = sdl2_keysym_to_xk(e);
	if (keysym == XK_VoidSymbol || keysym > NELEM(kbd_map)) {
		printf("kbd (cadet@sdl2): unable to translate to keysym (keysym = 0%o)\n", keysym);
		return;
	}
	if (kbd_type == 0) {
		if (!keydown)
			return;
		bi = 0;
		int mod = SDL_GetModState();
		if (mod & KMOD_SHIFT)
			knight_process_bucky(ShiftMapIndex, &bi);
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//			knight_process_bucky(Mod3MapIndex, &bi);
//		if (mod & Mod4Mask)
//			knight_process_bucky(Mod4MapIndex, &bi);
//		if (mod & Mod5Mask)
//			knight_process_bucky(Mod5MapIndex, &bi);
		knight_process_key(e.keysym.sym, bi, keydown);
	} else {
		bi = sdl2_bucky(e.keysym.mod);
		cadet_process_key(keysym, bi, keydown);
	}
}

void
sdl2_event(void)
{







|







207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//			knight_process_bucky(Mod3MapIndex, &bi);
//		if (mod & Mod4Mask)
//			knight_process_bucky(Mod4MapIndex, &bi);
//		if (mod & Mod5Mask)
//			knight_process_bucky(Mod5MapIndex, &bi);
		knight_process_key(e.keysym.sym, bi, keydown);
	} else {
		bi = sdl2_bucky(/* keysym */);
		cadet_process_key(keysym, bi, keydown);
	}
}

void
sdl2_event(void)
{

Changes to x11.c.

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
	idle_keyboard_activity();
	XLookupString(&e->xkey, (char *)buf, sizeof(buf), &keysym, &status);
	keycode = x11_keysym_to_keycode(keysym);
	if (keycode == NoSymbol || keysym > NELEM(kbd_map)) {
		printf("kbd (cadet@x11): unable to translate to keycode (keysym = 0%o)\n", keysym);
		return;
	}

	if (kbd_type == 0) {
		if (!keydown)
			return;
		bi = 0;
		if (e->xkey.state & ShiftMask)
			knight_process_bucky(ShiftMapIndex, &bi);
		if (e->xkey.state & LockMask)







<







101
102
103
104
105
106
107

108
109
110
111
112
113
114
	idle_keyboard_activity();
	XLookupString(&e->xkey, (char *)buf, sizeof(buf), &keysym, &status);
	keycode = x11_keysym_to_keycode(keysym);
	if (keycode == NoSymbol || keysym > NELEM(kbd_map)) {
		printf("kbd (cadet@x11): unable to translate to keycode (keysym = 0%o)\n", keysym);
		return;
	}

	if (kbd_type == 0) {
		if (!keydown)
			return;
		bi = 0;
		if (e->xkey.state & ShiftMask)
			knight_process_bucky(ShiftMapIndex, &bi);
		if (e->xkey.state & LockMask)