usim

Check-in [032a512225]
Login

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

Overview
Comment:Move allup key handling to respective backend.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ams/sdl
Files: files | file ages | folders
SHA3-256: 032a512225a253c44b4ffb307cdcc4b5eb8be506e0cfb616bc3880c4b9cba404
User & Date: ams 2024-06-19 06:45:34
Context
2024-06-19
07:03
Minor cleanups. check-in: c56a574a07 user: ams tags: ams/sdl
06:45
Move allup key handling to respective backend. check-in: 032a512225 user: ams tags: ams/sdl
2024-06-18
15:01
README.md, lmdf.text: Update. check-in: bfcbe36d94 user: ams tags: ams/sdl
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to cadet.c.

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define CADET_MODELOCK		03

unsigned short cadet_kbd_map[256][2];
unsigned short cadet_modifier_map[11];

int cadet_shifts = CADET_IX_UNSHIFT;

static void
cadet_allup_event(int mods)
{
	int v;

	v = (1 << 15) | (mods & 01777);
	if (iob_csr & (1 << 5))
		kbd_queue_key_event(v);	/* Already something there, queue this. */







|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#define CADET_MODELOCK		03

unsigned short cadet_kbd_map[256][2];
unsigned short cadet_modifier_map[11];

int cadet_shifts = CADET_IX_UNSHIFT;

void
cadet_allup_event(int mods)
{
	int v;

	v = (1 << 15) | (mods & 01777);
	if (iob_csr & (1 << 5))
		kbd_queue_key_event(v);	/* Already something there, queue this. */
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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
//			if (i >= SDLK_NUMLOCK && i <= SDLK_COMPOSE)
//				break;
//			allup = false;
		break;
	}
}

#ifdef WITH_X11
/*
 * Check if all keys are up - too expensive?
 */
static bool
cadet_allup_key(void)
{
	bool allup;
	int mods;
	int shifts;
	XModifierKeymap *modmap;
	char keymap[32];

	allup = true;
	mods = 0;
	shifts = 0;
	modmap = x11_get_modifier_mapping();
	x11_query_keymap(keymap);
	/*
	 * For each modifier (and in turn, each keycode associated
	 * with that modifier), check and see if it is down.  If that
	 * is the case, clear the set key from KEYMAP.
	 *
	 * Also keep track if we should do an all-up event, and track
	 * the modifiers for later.
	 */
	for (int modifier = 0; modifier < 8; modifier++) {
		int bucky;

		bucky = modifier_map[modifier];
		for (int i = 0; i < modmap->max_keypermod; i++) {
			KeyCode keycode;

			keycode = modmap->modifiermap[modifier * modmap->max_keypermod + i];
			if (keymap[keycode / 8] & (1 << keycode % 8)) {
				keymap[keycode / 8] &= ~(1 << keycode % 8);	/* Clear the key in KEYMAP. */
				DEBUG(TRACE_KBD, "cadet_allup_key() - bucky pressed (%d); keycode = %d\n", bucky, keycode);
				cadet_press_bucky(bucky, &mods, &shifts);
			}
		}
	}
	XFreeModifiermap(modmap);
	/*
	 * Check if any other key than modifiers (that got cleared
	 * above) are set.  If that is the case, do not generate an
	 * all-up event.
	 */
	for (int i = 0; i < 32; i++) {
		if (keymap[i] != 0) {
			DEBUG(TRACE_KBD, "cadet_allup_key() - found a key that is up which is not a shift; keymap[%d] = 0%o\n", i, keymap[i]);
			allup = false;
			break;
		}
	}
	if (allup == true) {
		DEBUG(TRACE_KBD, "cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;	 /* Keep track of shifts.  */
		cadet_allup_event(mods); /* Generate all-up event. */
	}
	return allup;
}
#elif WITH_SDL1
bool
cadet_allup_key(void)
{
	bool allup;
	int mods;
	int shifts;

	int statesize;
	Uint8 *state;

	allup = true;
	mods = 0;
	shifts = 0;

	state = SDL_GetKeyState(&statesize);
	for (int i = 0; allup && i < statesize; i++) {
		int bucky;

		if (state[i] != 1)
			continue;
		bucky = modifier_map[i];
		DEBUG(TRACE_KBD, "cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i);
		cadet_press_bucky(bucky, &mods, &shifts);
	}
	if (allup == true) {
		DEBUG(TRACE_KBD, "cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;
		cadet_allup_event(mods);
	}
	return allup;
}
#elif WITH_SDL2
bool
cadet_allup_key(void)
{
	bool allup;
	int mods;
	int shifts;

	int statesize;
	Uint8 *state;

	allup = true;
	mods = 0;
	shifts = 0;

	state = SDL_GetKeyboardState(&statesize);
	for (int i = 0; allup && i < statesize; i++) {
		int bucky;

		if (state[i] != 1)
			continue;
		bucky = modifier_map[i];
		DEBUG(TRACE_KBD, "cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i);
		cadet_press_bucky(bucky, &mods, &shifts);
	}
	if (allup == true) {
		DEBUG(TRACE_KBD, "cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;
		cadet_allup_event(mods);
	}
	return allup;
}
#endif

static void
cadet_process_shift(int scc, int keydown)
{
	DEBUG(TRACE_KBD, "cadet_process_shift(scc = 0%o, keydown = %d)\n", scc, keydown);
	if (keydown) {
		if ((scc == CADET_LEFT_GREEK) || (scc == CADET_RIGHT_GREEK))
			cadet_shifts |= (1 << CADET_IX_GREEK);







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







133
134
135
136
137
138
139































































































































140
141
142
143
144
145
146
//			if (i >= SDLK_NUMLOCK && i <= SDLK_COMPOSE)
//				break;
//			allup = false;
		break;
	}
}
































































































































static void
cadet_process_shift(int scc, int keydown)
{
	DEBUG(TRACE_KBD, "cadet_process_shift(scc = 0%o, keydown = %d)\n", scc, keydown);
	if (keydown) {
		if ((scc == CADET_LEFT_GREEK) || (scc == CADET_RIGHT_GREEK))
			cadet_shifts |= (1 << CADET_IX_GREEK);
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
	}
}

void
cadet_process_key(
	int keysym,	  /* keysym, acts as index into kbd_map */
	int bi,		  /* bucky, acts as index into modifier_map */
	int keydown

	)
{
	int lmchar;		/* Lisp Machine charachter to insert */
	int scc;		/* Space Cadet scancode. */
	int wantshift;		/* Index into second column in cadet_kbd_map. */
	int shkey;		/* Shift key being pressed. */
	int oshift;

	if (!keydown && cadet_allup_key() == true)
		return;
	oshift = cadet_shifts;
	DEBUG(TRACE_KBD, "kbd (cadet): keysym = 0%o, bi = %d\n", keysym, bi);
	if (bi != -1) {
		int bucky;

		bucky = modifier_map[bi];







|
>








|







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
	}
}

void
cadet_process_key(
	int keysym,	  /* keysym, acts as index into kbd_map */
	int bi,		  /* bucky, acts as index into modifier_map */
	int keydown,
	int (*allup_key)(void)
	)
{
	int lmchar;		/* Lisp Machine charachter to insert */
	int scc;		/* Space Cadet scancode. */
	int wantshift;		/* Index into second column in cadet_kbd_map. */
	int shkey;		/* Shift key being pressed. */
	int oshift;

	if (!keydown && allup_key() == true)
		return;
	oshift = cadet_shifts;
	DEBUG(TRACE_KBD, "kbd (cadet): keysym = 0%o, bi = %d\n", keysym, bi);
	if (bi != -1) {
		int bucky;

		bucky = modifier_map[bi];

Changes to cadet.h.

1
2
3
4
5
6
7
8


9
10
11
12
#pragma once

#if WITH_X11
#include "x11.h"
#elif WITH_SDL1
#include "sdl1.h"
#endif



extern void cadet_init(void);
extern void cadet_process_key(int, int, int);

extern void cadet_queue_all_keys_up(void);








>
>

|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once

#if WITH_X11
#include "x11.h"
#elif WITH_SDL1
#include "sdl1.h"
#endif

int cadet_shifts;

extern void cadet_init(void);
extern void cadet_process_key(int, int, int, 	int (*allup_key)(void));

extern void cadet_queue_all_keys_up(void);

Changes to knight.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* knight.c --- Knight (aka old) keyboard */

#include <err.h>
#include <stdio.h>
#include <string.h>

#include "kbd.h"
#include "utrace.h"
#if WITH_X11
#include "x11.h"
#elif WITH_SDL1
#include "sdl1.h"
#endif

#define KNIGHT_VANILLA		0	/* VANILLA */
#define KNIGHT_SHIFT		0300	/* SHIFT BITS */
#define KNIGHT_TOP		01400	/* TOP BITS */
#define KNIGHT_CONTROL		06000	/* CONTROL BITS */
#define KNIGHT_META		030000	/* META BITS */
#define KNIGHT_SHIFT_LOCK	040000	/* SHIFT LOCK */








<
<
<
<
<







1
2
3
4
5
6
7
8





9
10
11
12
13
14
15
/* knight.c --- Knight (aka old) keyboard */

#include <err.h>
#include <stdio.h>
#include <string.h>

#include "kbd.h"
#include "utrace.h"






#define KNIGHT_VANILLA		0	/* VANILLA */
#define KNIGHT_SHIFT		0300	/* SHIFT BITS */
#define KNIGHT_TOP		01400	/* TOP BITS */
#define KNIGHT_CONTROL		06000	/* CONTROL BITS */
#define KNIGHT_META		030000	/* META BITS */
#define KNIGHT_SHIFT_LOCK	040000	/* SHIFT LOCK */

Changes to sdl1.c.

251
252
253
254
255
256
257
































258
259
260
261
262
263
264
	}
}

void
sdl1_beep(int v)
{
}

































void
sdl1_init(void)
{
	NOTICE(TRACE_USIM, "tv: using SDL1 backend for monitor and keyboard\n");

	Foreground = 0xff; // White







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
	}
}

void
sdl1_beep(int v)
{
}

bool
cadet_allup_key(void)
{
	bool allup;
	int mods;
	int shifts;

	int statesize;
	Uint8 *state;

	allup = true;
	mods = 0;
	shifts = 0;

	state = SDL_GetKeyState(&statesize);
	for (int i = 0; allup && i < statesize; i++) {
		int bucky;

		if (state[i] != 1)
			continue;
		bucky = modifier_map[i];
		DEBUG(TRACE_KBD, "cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i);
		cadet_press_bucky(bucky, &mods, &shifts);
	}
	if (allup == true) {
		DEBUG(TRACE_KBD, "cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;
		cadet_allup_event(mods);
	}
	return allup;
}

void
sdl1_init(void)
{
	NOTICE(TRACE_USIM, "tv: using SDL1 backend for monitor and keyboard\n");

	Foreground = 0xff; // White

Changes to sdl2.c.

175
176
177
178
179
180
181
































182
183
184
185
186
187
188
//	case SDLK_RSUPER: return XK_Super_R;
//	case SDLK_LHYPER: return XK_Hyper_L;
//	case SDLK_RHYPER: return XK_Hyper_R;

	default: return XK_VoidSymbol;
	}
}

































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








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//	case SDLK_RSUPER: return XK_Super_R;
//	case SDLK_LHYPER: return XK_Hyper_L;
//	case SDLK_RHYPER: return XK_Hyper_R;

	default: return XK_VoidSymbol;
	}
}

bool
cadet_allup_key(void)
{
	bool allup;
	int mods;
	int shifts;

	int statesize;
	Uint8 *state;

	allup = true;
	mods = 0;
	shifts = 0;

	state = SDL_GetKeyboardState(&statesize);
	for (int i = 0; allup && i < statesize; i++) {
		int bucky;

		if (state[i] != 1)
			continue;
		bucky = modifier_map[i];
		DEBUG(TRACE_KBD, "cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i);
		cadet_press_bucky(bucky, &mods, &shifts);
	}
	if (allup == true) {
		DEBUG(TRACE_KBD, "cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;
		cadet_allup_event(mods);
	}
	return allup;
}

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

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//		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);
		cadet_process_key(keysym /* xk_keysym*/, bi, keydown);
	}
}

void
sdl2_event(void)
{
	SDL_Event ev;







|







247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//		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);
		cadet_process_key(keysym /* xk_keysym*/, bi, keydown, &cadet_allup_key);
	}
}

void
sdl2_event(void)
{
	SDL_Event ev;

Changes to x11.c.

180
181
182
183
184
185
186





























































187
188
189
190
191
192
193
	case IDLE_WORKING:
		XSetForeground(display, idle_gc, Background);
		break;
	}
	XDrawLine(display, window, idle_gc, tv_width - width - right, tv_height - bottom, tv_width - right, tv_height - bottom);
}






























































void
x11_beep(void)
{
	XKeyboardControl kc;
	XKeyboardControl okc;
	static int onoff = 100;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
	case IDLE_WORKING:
		XSetForeground(display, idle_gc, Background);
		break;
	}
	XDrawLine(display, window, idle_gc, tv_width - width - right, tv_height - bottom, tv_width - right, tv_height - bottom);
}

/*
 * Check if all keys are up - too expensive?
 */
bool
cadet_allup_key(void)
{
	bool allup;
	int mods;
	int shifts;
	XModifierKeymap *modmap;
	char keymap[32];

	allup = true;
	mods = 0;
	shifts = 0;
	modmap = x11_get_modifier_mapping();
	x11_query_keymap(keymap);
	/*
	 * For each modifier (and in turn, each keycode associated
	 * with that modifier), check and see if it is down.  If that
	 * is the case, clear the set key from KEYMAP.
	 *
	 * Also keep track if we should do an all-up event, and track
	 * the modifiers for later.
	 */
	for (int modifier = 0; modifier < 8; modifier++) {
		int bucky;

		bucky = modifier_map[modifier];
		for (int i = 0; i < modmap->max_keypermod; i++) {
			KeyCode keycode;

			keycode = modmap->modifiermap[modifier * modmap->max_keypermod + i];
			if (keymap[keycode / 8] & (1 << keycode % 8)) {
				keymap[keycode / 8] &= ~(1 << keycode % 8);	/* Clear the key in KEYMAP. */
				DEBUG(TRACE_KBD, "cadet_allup_key() - bucky pressed (%d); keycode = %d\n", bucky, keycode);
				cadet_press_bucky(bucky, &mods, &shifts);
			}
		}
	}
	XFreeModifiermap(modmap);
	/*
	 * Check if any other key than modifiers (that got cleared
	 * above) are set.  If that is the case, do not generate an
	 * all-up event.
	 */
	for (int i = 0; i < 32; i++) {
		if (keymap[i] != 0) {
			DEBUG(TRACE_KBD, "cadet_allup_key() - found a key that is up which is not a shift; keymap[%d] = 0%o\n", i, keymap[i]);
			allup = false;
			break;
		}
	}
	if (allup == true) {
		DEBUG(TRACE_KBD, "cadet_allup_key() - all-up event; mods = 0%o, shifts = 0%o\n", mods, shifts);
		cadet_shifts = shifts;	 /* Keep track of shifts.  */
		cadet_allup_event(mods); /* Generate all-up event. */
	}
	return allup;
}

void
x11_beep(void)
{
	XKeyboardControl kc;
	XKeyboardControl okc;
	static int onoff = 100;