-void draw_keys_window (struct Win * win) {
-// Draw keybinding window.
- struct World * world = (struct World *) win->data;
- struct KeysWinData * keyswindata = (struct KeysWinData *) world->keyswindata;
- struct KeyBinding * keybindings = world->keybindings;
- int height_av = win->height - 1;
- int width_av = win->width - 1;
- int offset = 0;
- if (keyswindata->max >= height_av) {
- if (keyswindata->select > height_av / 2)
- if (keyswindata->select < (keyswindata->max - (height_av / 2)))
- offset = keyswindata->select - (height_av / 2);
- else
- offset = keyswindata->max - height_av + 1; }
- int keydescwidth = 9; // max length assured by get_keyname()
- char * keydesc = malloc(keydescwidth + 1);
- attr_t attri;
- int y, x;
- char * keyname;
- for (y = 0; 0 != keybindings[offset + y].name && y < height_av; y++) {
- attri = 0;
- if (y == keyswindata->select - offset) {
- attri = A_REVERSE;
- if (1 == keyswindata->edit)
- attri = attri | A_BLINK; }
- keyname = get_keyname(keybindings[y + offset].key);
- snprintf(keydesc, keydescwidth + 1, "%-9s", keyname);
- free(keyname);
- for (x = 0; x < width_av; x++)
- if (strlen(keydesc) > x)
- mvwaddch(win->curses_win, y + 1, x + win->border_left, keydesc[x] | attri);
- else if (strlen(keydesc) < x && x < strlen(keybindings[y + offset].name) + strlen(keydesc) + 1)
- mvwaddch(win->curses_win, y + 1, x + win->border_left, keybindings[y + offset].name[x - strlen(keydesc) - 1] | attri);
- else
- mvwaddch(win->curses_win, y + 1, x + win->border_left, ' ' | attri); }
- free(keydesc);
- if (y < height_av)
- for (; y < height_av; y++)
- for (x = 0; x < width_av; x++)
- mvwaddch(win->curses_win, y + 1, x + win->border_left, ' '); }
+void keyswin_mod_key (struct World * world, struct WinMeta * win_meta) {
+// In keybindings window, mark selection modifiable, modify key. Ensure max of three digits in key code field.
+ world->keyswindata->edit = 1;
+ draw_all_windows (win_meta);
+ int key = getch();
+ if (key < 1000)
+ world->keybindings[world->keyswindata->select].key = key;
+ world->keyswindata->edit = 0; }