#include "keybindings.h"
#include <ncurses.h> /* keycode defines, cbreak(), halfdelay(), getch() */
+#include <stddef.h> /* NULL */
#include <stdio.h> /* FILE, sprintf(), snprintf() */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include <stdlib.h> /* free(), atoi() */
-#include <string.h> /* strlen(), strchr(), strcmp(), memcpy() */
+#include <string.h> /* strlen(), strchr() */
#include "../common/readwrite.h" /* try_fopen(), textfile_sizes(), try_fgets(),
* try_fclose(), try_fclose_unlink_rename(),
* try_fwrite()
*/
-#include "../common/try_malloc.h" /* for try_malloc() */
+#include "../common/try_malloc.h" /* try_malloc() */
+#include "wincontrol.h" /* get_winconf_by_win() */
#include "windows.h" /* draw_all_wins() */
#include "world.h" /* global world */
/* Return number of keybindings in keybindings chain from "kb_p" on. */
static uint16_t get_n_of_keybs(struct KeyBinding * kb_p);
+/* Return pointer to global keybindings or to keybindings for wingeometry config
+ * (c = "g") or winkeys config (c = "k") or active window's keybindings ("w").
+ */
+static struct KeyBindingDB * char_selected_kb_db(char c);
+
/* If "keycode_given" equals "keycode_match", copy "keyname_match" to "keyname"
* and return 1; otherwise return 0.
*/
+static struct KeyBindingDB * char_selected_kb_db(char c)
+{
+ struct KeyBindingDB * kbd;
+ kbd = &world.kb_global;
+ if ('g' == c)
+ {
+ kbd = &world.kb_wingeom;
+ }
+ else if ('k' == c)
+ {
+ kbd = &world.kb_winkeys;
+ }
+ else if ('w' == c)
+ {
+ struct WinConf * wc = get_winconf_by_win(world.wmeta.active);
+ kbd = &wc->kb;
+ }
+ return kbd;
+}
+
+
+
static uint8_t try_keycode(uint16_t keycode_given, char * keyname,
uint16_t keycode_match, char * keyname_match)
{
-extern char * get_actionname_to_keycode(struct KeyBinding * kb_p, uint16_t key)
+extern struct Command * get_command_to_keycode(struct KeyBinding * kb_p,
+ uint16_t key)
{
while (0 != kb_p)
{
if (key == kb_p->key)
{
- return kb_p->name;
+ return kb_p->command;
}
kb_p = kb_p->next;
}
-extern uint16_t get_keycode_to_action(struct KeyBinding * kb_p, char * name)
-{
- while (0 != kb_p)
- {
- if (0 == strcmp(kb_p->name, name))
- {
- return kb_p->key;
- }
- kb_p = kb_p->next;
- }
- return 0;
-}
-
-
-
-extern char * get_name_to_keycode(uint16_t keycode)
+extern char * get_keyname_to_keycode(uint16_t keycode)
{
char * f_name = "get_name_to_keycode()";
char * keyname = try_malloc(15, f_name); /* FIXME: Why 15? */
kb_p->next = 0;
kb_p->key = atoi(command);
cmdptr = strchr(command, ' ') + 1;
- kb_p->name = try_malloc(strlen(cmdptr), f_name);
- memcpy(kb_p->name, cmdptr, strlen(cmdptr) - 1);
- kb_p->name[strlen(cmdptr) - 1] = '\0';
+ cmdptr[strlen(cmdptr) - 1] = '\0';
+ kb_p->command = get_command(cmdptr);
loc_last_ptr = & kb_p->next;
}
try_fclose(file, f_name);
struct KeyBinding * kb_p = kbd->kbs;
while (0 != kb_p)
{
- if (strlen(kb_p->name) > linemax)
+ if (strlen(kb_p->command->dsc_short) > linemax)
{
- linemax = strlen(kb_p->name);
+ linemax = strlen(kb_p->command->dsc_short);
}
kb_p = kb_p->next;
}
kb_p = kbd->kbs;
while (0 != kb_p)
{
- snprintf(line, linemax, "%d %s\n", kb_p->key, kb_p->name);
+ snprintf(line, linemax, "%d %s\n", kb_p->key, kb_p->command->dsc_short);
try_fwrite(line, sizeof(char), strlen(line), file, f_name);
kb_p = kb_p->next;
}
{
free_keybindings(kb_p);
}
- free(kb_start->name);
free(kb_start);
}
-extern void mod_selected_keyb(struct KeyBindingDB * kbd)
+extern void mod_selected_keyb(char kb_c)
{
+ struct KeyBindingDB * kbd = char_selected_kb_db(kb_c);
kbd->edit = 1;
draw_all_wins();
cbreak();
-extern void move_keyb_mod_selection(struct KeyBindingDB * kbd, char dir)
+extern void move_keyb_selection(char kb_c, char dir)
{
+ struct KeyBindingDB * kbd = char_selected_kb_db(kb_c);
if ('u' == dir && kbd->select > 0)
{
kbd->select--;