Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Initial hack for handling all-up keys on Cadet. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | ams/sdl1 |
Files: | files | file ages | folders |
SHA3-256: |
a2d5e20fe1ee2e9761193c115dbacb16 |
User & Date: | ams 2024-06-12 07:32:44 |
Context
2024-06-12
| ||
11:53 | ucfg.c: Include SDL1 and SDL2 headers. check-in: 519b4720fe user: ams tags: ams/sdl1 | |
07:32 | Initial hack for handling all-up keys on Cadet. check-in: a2d5e20fe1 user: ams tags: ams/sdl1 | |
2024-06-11
| ||
11:19 | Half working SDL2 keyboard input. check-in: ee2075a420 user: ams tags: ams/sdl1 | |
Changes
Changes to cadet.c.
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include "misc.h" #include "ucode.h" #include "utrace.h" #if WITH_X11 #include "x11.h" #elif WITH_SDL1 #include "sdl1.h" #endif /* * Second index in CADET_KBD_MAP, gives which shift must be generated. */ #define CADET_IX_UNSHIFT 0 #define CADET_IX_SHIFT 1 | > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include "misc.h" #include "ucode.h" #include "utrace.h" #if WITH_X11 #include "x11.h" #elif WITH_SDL1 #include "sdl1.h" #elif WITH_SDL2 #include "sdl2.h" #endif /* * Second index in CADET_KBD_MAP, gives which shift must be generated. */ #define CADET_IX_UNSHIFT 0 #define CADET_IX_SHIFT 1 |
︙ | ︙ | |||
118 119 120 121 122 123 124 | bucky = x11_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. */ | | | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | bucky = x11_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. */ printf("cadet_allup_key() - bucky pressed (%d); keycode = %d\n", bucky, keycode); switch (bucky) { case KBD_SHIFT: mods |= CADET_ALLUP_SHIFT; shifts |= (1 << CADET_IX_SHIFT); break; case KBD_TOP: mods |= CADET_ALLUP_TOP; |
︙ | ︙ | |||
156 157 158 159 160 161 162 | case KBD_HYPER: mods |= CADET_ALLUP_HYPER; break; case KBD_SUPER: mods |= CADET_ALLUP_SUPER; break; default: | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 274 275 276 | case KBD_HYPER: mods |= CADET_ALLUP_HYPER; break; case KBD_SUPER: mods |= CADET_ALLUP_SUPER; break; default: printf("kbd (cadet): unknown bucky key: 0%o\n", x11_modifier_map[modifier]); break; } } } } 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) { printf("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) { } #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 = sdl2_modifier_map[i]; printf("cadet_allup_key() - bucky pressed (%d), i = %d\n", bucky, i); switch (bucky) { case KBD_SHIFT: mods |= CADET_ALLUP_SHIFT; shifts |= (1 << CADET_IX_SHIFT); break; case KBD_TOP: mods |= CADET_ALLUP_TOP; shifts |= (1 << CADET_IX_TOP); break; case KBD_CONTROL: mods |= CADET_ALLUP_CONTROL; break; case KBD_META: mods |= CADET_ALLUP_META; break; case KBD_SHIFT_LOCK: mods |= CADET_ALLUP_CAPS_LOCK; break; case KBD_MODE_LOCK: mods |= CADET_ALLUP_MODELOCK; break; case KBD_GREEK: mods |= CADET_ALLUP_GREEK; shifts |= (1 << CADET_IX_GREEK); break; case KBD_REPEAT: break; case KBD_ALT_LOCK: mods |= CADET_ALLUP_ALTLOCK; break; case KBD_HYPER: mods |= CADET_ALLUP_HYPER; break; case KBD_SUPER: mods |= CADET_ALLUP_SUPER; break; default: printf("kbd (cadet): unknown bucky key: 0%o\n", sdl2_modifier_map[i]); /* Hack: ignore modifier key which isn't bound */ // if (i >= SDLK_NUMLOCK && i <= SDLK_COMPOSE) // break; allup = false; break; } } if (allup == true) { printf("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); |
︙ | ︙ |
Changes to sdl2.c.
︙ | ︙ | |||
215 216 217 218 219 220 221 | u_maxv = 0; } int sdl2_bucky(SDL_Keymod mod) { if (mod & KMOD_CTRL) return ControlMapIndex; | | | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | 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; return -1; } |
︙ | ︙ | |||
346 347 348 349 350 351 352 | // knight_process_bucky(sdl2_modifier_map[Mod4MapIndex], &bi); // if (e->xkey.state & Mod5Mask) // knight_process_bucky(sdl2_modifier_map[Mod5MapIndex], &bi); knight_process_key(e.keysym.sym, bi, keydown, sdl2_kbd_map, sdl2_modifier_map); } else { bi = sdl2_bucky(e.keysym.mod); keysym = sdl2_keysym_to_xk(e); | | | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | // knight_process_bucky(sdl2_modifier_map[Mod4MapIndex], &bi); // if (e->xkey.state & Mod5Mask) // knight_process_bucky(sdl2_modifier_map[Mod5MapIndex], &bi); knight_process_key(e.keysym.sym, bi, keydown, sdl2_kbd_map, sdl2_modifier_map); } else { bi = sdl2_bucky(e.keysym.mod); keysym = sdl2_keysym_to_xk(e); printf("bi = %d, keysym=%c -- 0%o (%c)\n", bi,keysym,keysym,keydown?'d':'u'); if (keysym == 0xffffff) return; cadet_process_key(keysym, bi, keydown, sdl2_kbd_map, sdl2_modifier_map); } } void sdl2_event(void) |
︙ | ︙ |
Changes to sdl2.h.
1 2 3 4 5 6 7 8 9 10 11 12 | #pragma once #include <SDL2/SDL.h> extern void sdl2_init(void); extern void sdl2_default_kbd_map(void); extern void sdl2_event(void); extern unsigned long Background; extern unsigned long Foreground; extern void accumulate_update(int, int, int, int); | > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #pragma once #include <SDL2/SDL.h> extern void sdl2_init(void); extern void sdl2_default_kbd_map(void); extern void sdl2_event(void); extern unsigned long Background; extern unsigned long Foreground; extern void accumulate_update(int, int, int, int); extern int sdl2_kbd_map[65535]; extern int sdl2_modifier_map[8]; |
Changes to x11.c.
︙ | ︙ | |||
105 106 107 108 109 110 111 | int bi; unsigned char buf[5]; idle_keyboard_activity(); XLookupString(&e->xkey, (char *)buf, sizeof(buf), &keysym, &status); keycode = x11_keysym_to_keycode(keysym); if (keycode == NoSymbol || keysym > NELEM(x11_kbd_map)) { | | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | int bi; unsigned char buf[5]; idle_keyboard_activity(); XLookupString(&e->xkey, (char *)buf, sizeof(buf), &keysym, &status); keycode = x11_keysym_to_keycode(keysym); if (keycode == NoSymbol || keysym > NELEM(x11_kbd_map)) { printf("kbd (cadet): unable to translate to x11 keycode (keysym = 0%o)\n", keysym); return; } if (kbd_type == 0) { if (!keydown) return; bi = 0; |
︙ | ︙ | |||
132 133 134 135 136 137 138 | if (e->xkey.state & Mod4Mask) knight_process_bucky(x11_modifier_map[Mod4MapIndex], &bi); if (e->xkey.state & Mod5Mask) knight_process_bucky(x11_modifier_map[Mod5MapIndex], &bi); knight_process_key(keysym, bi, keydown, x11_kbd_map, x11_modifier_map); } else { bi = x11_bucky(keycode); | | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | if (e->xkey.state & Mod4Mask) knight_process_bucky(x11_modifier_map[Mod4MapIndex], &bi); if (e->xkey.state & Mod5Mask) knight_process_bucky(x11_modifier_map[Mod5MapIndex], &bi); knight_process_key(keysym, bi, keydown, x11_kbd_map, x11_modifier_map); } else { bi = x11_bucky(keycode); printf("bi = %d, keysym=%c -- 0%o (%c)\n", bi,keysym,keysym,keydown?'d':'u'); cadet_process_key(keysym, bi, keydown, x11_kbd_map, x11_modifier_map); } } static int u_minh = 0x7fffffff; static int u_maxh; static int u_minv = 0x7fffffff; |
︙ | ︙ |