Crossfire Client, Trunk  R20996
keys.c File Reference
#include "client.h"
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include "main.h"
#include "proto.h"
#include "def-keys.h"
#include "image.h"
#include "gtk2proto.h"
#include "p_cmd.h"
+ Include dependency graph for keys.c:

Go to the source code of this file.

Data Structures

struct  keybind
 

Enumerations

KList Enum

EndOf UI Widgets

Changed to KLIST_* to avoid conflicts in Win2000 and up

enum  {
  KLIST_ENTRY, KLIST_KEY, KLIST_MODS, KLIST_SCOPE,
  KLIST_EDIT, KLIST_COMMAND, KLIST_KEY_ENTRY
}
 

Functions

static int keybind_overwrite_confirm (struct keybind *kb)
 
static void keybinding_get_data (guint32 *keysym, guint8 *flags, const char **command)
 
gboolean keybinding_selection_func (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer userdata)
 
void on_kb_scope_togglebutton_character_toggled (GtkToggleButton *toggle_button, gpointer user_data)
 
void on_kb_scope_togglebutton_global_toggled (GtkToggleButton *toggle_button, gpointer user_data)
 
void on_keybinding_button_bind_clicked (GtkButton *button, gpointer user_data)
 
void on_keybinding_button_clear_clicked (GtkButton *button, gpointer user_data)
 
void on_keybinding_button_close_clicked (GtkButton *button, gpointer user_data)
 
void on_keybinding_button_remove_clicked (GtkButton *button, gpointer user_data)
 
void on_keybinding_button_update_clicked (GtkButton *button, gpointer user_data)
 
void on_keybinding_checkbutton_any_clicked (GtkCheckButton *cb, gpointer user_data)
 
gboolean on_keybinding_entry_key_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 
void on_keybindings_activate (GtkMenuItem *menuitem, gpointer user_data)
 
void reset_keybinding_status (void)
 
void toggle_buttons_scope (int scope)
 
void toggle_keybind_scope (int scope, struct keybind *kb)
 
void update_keybinding_list (void)
 

Variables

UI Widgets

Widgets for the keybinding dialog

static GtkWidget * fire_label
 
static GtkWidget * run_label
 
static GtkWidget * keybinding_window
 
static GtkWidget * kb_scope_togglebutton_global
 
static GtkWidget * kb_scope_togglebutton_character
 
static GtkWidget * keybinding_checkbutton_any
 
static GtkWidget * keybinding_checkbutton_control
 
static GtkWidget * keybinding_checkbutton_shift
 
static GtkWidget * keybinding_checkbutton_alt
 
static GtkWidget * keybinding_checkbutton_meta
 
static GtkWidget * keybinding_checkbutton_edit
 
static GtkWidget * keybinding_entry_key
 
static GtkWidget * keybinding_entry_command
 
static GtkWidget * keybinding_treeview
 
static GtkWidget * keybinding_button_remove
 
static GtkWidget * keybinding_button_update
 
static GtkWidget * keybinding_button_bind
 
static GtkListStore * keybinding_store
 
static GtkTreeSelection * keybinding_selection
 
GtkWidget * spinbutton_count
 
GtkWidget * entry_commands
 

Bind Log

EndOf KList Enum

#define MAX_HISTORY   50
 
#define MAX_COMMAND_LEN   256
 
char history [MAX_HISTORY][MAX_COMMAND_LEN]
 
static int cur_history_position = 0
 
static int scroll_history_position = 0
 

key_entry struct

EndOf Bind Log

A keybinding hash record structure.

#define KEYF_MOD_SHIFT   (1 << 0)
 
#define KEYF_MOD_CTRL   (1 << 1)
 
#define KEYF_MOD_ALT   (1 << 2)
 
#define KEYF_MOD_META   (1 << 3)
 
#define KEYF_MOD_MASK
 
#define KEYF_ANY   (1 << 4)
 
#define KEYF_EDIT   (1 << 5)
 
#define KEYF_R_GLOBAL   (1 << 6)
 
#define KEYF_R_CHAR   (1 << 7)
 
#define KEYHASH   257
 
#define EKEYBIND_NOMEM   1
 
static guint32 firekeysym [2]
 
static guint32 runkeysym [2]
 
static guint32 commandkeysym
 
static guint32 * bind_keysym
 
static guint32 prevkeysym
 
static guint32 nextkeysym
 
static guint32 completekeysym
 
static guint32 altkeysym [2]
 
static guint32 metakeysym [2]
 
static guint32 cancelkeysym
 
static int bind_flags = 0
 
static char bind_buf [MAX_BUF]
 
const char *const directions [9]
 
static struct keybindkeys_global [KEYHASH]
 
static struct keybindkeys_char [KEYHASH]
 
static bool debounce = false
 
static int keybind_remove (struct keybind *entry)
 
static void keybind_free (struct keybind **entry)
 
static struct keybindkeybind_find (guint32 keysym, unsigned int flags, int scope)
 
static int keybind_insert (guint32 keysym, unsigned int flags, const char *command)
 
static void parse_keybind_line (char *buf, int line, unsigned int scope_flag)
 
static void init_default_keybindings ()
 
static int parse_keys_file (char *filename, unsigned int scope_flag)
 
void keybindings_init (const char *character_name)
 
void keys_init (GtkWidget *window_root)
 
static void parse_key_release (guint32 keysym)
 
static void parse_key (char key, guint32 keysym)
 
static void get_key_modchars (struct keybind *kb, int save_mode, char *buf)
 
static char * get_key_info (struct keybind *kb, int save_mode)
 
static void show_keys (void)
 
void bind_key (char *params)
 
static void save_individual_key (FILE *fp, struct keybind *kb, KeyCode kc)
 
static void save_keys (void)
 
static void configure_keys (guint32 keysym)
 
static void unbind_usage (void)
 
void unbind_key (const char *params)
 
void focusoutfunc (GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
 
void keyrelfunc (GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
 
void keyfunc (GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
 
void x_set_echo (void)
 
void draw_prompt (const char *str)
 
void gtk_command_history (int direction)
 
void gtk_complete_command (void)
 
void on_entry_commands_activate (GtkEntry *entry, gpointer user_data)
 

Detailed Description

Handles most of the keyboard related functions - binding and unbinding keys, and handling keypresses and looking up the keys.

Definition in file keys.c.

Macro Definition Documentation

◆ KEYF_ANY

#define KEYF_ANY   (1 << 4)

◆ KEYF_EDIT

#define KEYF_EDIT   (1 << 5)

◆ KEYF_MOD_ALT

#define KEYF_MOD_ALT   (1 << 2)

◆ KEYF_MOD_CTRL

#define KEYF_MOD_CTRL   (1 << 1)

◆ KEYF_MOD_MASK

#define KEYF_MOD_MASK
Value:
KEYF_MOD_CTRL | \
KEYF_MOD_ALT | \
KEYF_MOD_META)
#define KEYF_MOD_SHIFT
Definition: keys.c:139

Definition at line 143 of file keys.c.

Referenced by get_key_modchars(), keybind_find(), and update_keybinding_list().

◆ KEYF_MOD_META

#define KEYF_MOD_META   (1 << 3)

◆ KEYF_MOD_SHIFT

#define KEYF_MOD_SHIFT   (1 << 0)

◆ KEYF_R_CHAR

#define KEYF_R_CHAR   (1 << 7)

Character specific

Definition at line 153 of file keys.c.

Referenced by keybindings_init(), toggle_keybind_scope(), and update_keybinding_list().

◆ KEYF_R_GLOBAL

◆ KEYHASH

◆ MAX_COMMAND_LEN

#define MAX_COMMAND_LEN   256

Definition at line 87 of file keys.c.

Referenced by on_entry_commands_activate().

◆ MAX_HISTORY

#define MAX_HISTORY   50

Definition at line 86 of file keys.c.

Referenced by gtk_command_history(), keybindings_init(), and on_entry_commands_activate().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
KLIST_ENTRY 
KLIST_KEY 
KLIST_MODS 
KLIST_SCOPE 
KLIST_EDIT 
KLIST_COMMAND 
KLIST_KEY_ENTRY 

Definition at line 74 of file keys.c.

Variable Documentation

◆ altkeysym

guint32 altkeysym[2]
static

◆ bind_buf

char bind_buf[MAX_BUF]
static

◆ bind_flags

int bind_flags = 0
static

Definition at line 124 of file keys.c.

Referenced by bind_key(), and configure_keys().

◆ bind_keysym

guint32 * bind_keysym
static

Definition at line 120 of file keys.c.

Referenced by bind_key(), and configure_keys().

◆ cancelkeysym

guint32 cancelkeysym
static

Definition at line 120 of file keys.c.

Referenced by keybindings_init(), and keyfunc().

◆ commandkeysym

guint32 commandkeysym
static

Definition at line 120 of file keys.c.

Referenced by bind_key(), keybindings_init(), parse_key(), parse_keybind_line(), and show_keys().

◆ completekeysym

guint32 completekeysym
static

Definition at line 120 of file keys.c.

Referenced by bind_key(), keybindings_init(), keyfunc(), parse_keybind_line(), save_keys(), and show_keys().

◆ cur_history_position

int cur_history_position = 0
static

Definition at line 90 of file keys.c.

Referenced by gtk_command_history(), and on_entry_commands_activate().

◆ directions

const char* const directions[9]

Array for direction strings for each numeric direction.

Definition at line 36 of file player.c.

Referenced by keybind_insert().

◆ entry_commands

GtkWidget* entry_commands

◆ fire_label

GtkWidget* fire_label
static

Definition at line 50 of file keys.c.

Referenced by focusoutfunc(), keyfunc(), keys_init(), parse_key(), and parse_key_release().

◆ firekeysym

guint32 firekeysym[2]
static

◆ history

char history[MAX_HISTORY][MAX_COMMAND_LEN]

Definition at line 88 of file keys.c.

Referenced by gtk_command_history(), keybindings_init(), and on_entry_commands_activate().

◆ kb_scope_togglebutton_character

GtkWidget * kb_scope_togglebutton_character
static

◆ kb_scope_togglebutton_global

GtkWidget * kb_scope_togglebutton_global
static

◆ keybinding_button_bind

GtkWidget * keybinding_button_bind
static

Definition at line 50 of file keys.c.

Referenced by keys_init().

◆ keybinding_button_remove

GtkWidget * keybinding_button_remove
static

Definition at line 50 of file keys.c.

Referenced by keybinding_selection_func(), keys_init(), and reset_keybinding_status().

◆ keybinding_button_update

GtkWidget * keybinding_button_update
static

Definition at line 50 of file keys.c.

Referenced by keybinding_selection_func(), keys_init(), and reset_keybinding_status().

◆ keybinding_checkbutton_alt

◆ keybinding_checkbutton_any

GtkWidget * keybinding_checkbutton_any
static

◆ keybinding_checkbutton_control

◆ keybinding_checkbutton_edit

GtkWidget * keybinding_checkbutton_edit
static

◆ keybinding_checkbutton_meta

◆ keybinding_checkbutton_shift

◆ keybinding_entry_command

GtkWidget * keybinding_entry_command
static

◆ keybinding_entry_key

GtkWidget * keybinding_entry_key
static

◆ keybinding_selection

◆ keybinding_store

GtkListStore* keybinding_store
static

Bound key list for bind dialog.

Definition at line 60 of file keys.c.

Referenced by keys_init(), and update_keybinding_list().

◆ keybinding_treeview

GtkWidget * keybinding_treeview
static

Definition at line 50 of file keys.c.

Referenced by keys_init().

◆ keybinding_window

GtkWidget * keybinding_window
static

◆ keys_char

struct keybind * keys_char[KEYHASH]
static

Definition at line 167 of file keys.c.

◆ keys_global

struct keybind* keys_global[KEYHASH]
static

Will hold the keybindings into two separate hashes depending on the scope they afect (global or character). This allows editting both scopes at the same time and switch scopes for a certain binding with ease.

Platform independence defines that we can't use keycodes. Instead, make it a hash, and set KEYHASH to a prime number for this purpose.

Definition at line 167 of file keys.c.

◆ metakeysym

guint32 metakeysym[2]
static

◆ nextkeysym

guint32 nextkeysym
static

Definition at line 120 of file keys.c.

Referenced by bind_key(), keybindings_init(), keyfunc(), parse_keybind_line(), save_keys(), and show_keys().

◆ prevkeysym

guint32 prevkeysym
static

Definition at line 120 of file keys.c.

Referenced by bind_key(), keybindings_init(), keyfunc(), parse_keybind_line(), save_keys(), and show_keys().

◆ run_label

GtkWidget * run_label
static

Definition at line 50 of file keys.c.

Referenced by focusoutfunc(), keyfunc(), keys_init(), parse_key(), and parse_key_release().

◆ runkeysym

guint32 runkeysym[2]
static

◆ scroll_history_position

int scroll_history_position = 0
static

Definition at line 90 of file keys.c.

Referenced by gtk_command_history(), and on_entry_commands_activate().

◆ spinbutton_count

GtkWidget* spinbutton_count

Definition at line 63 of file keys.c.

Referenced by keys_init(), list_item_action(), on_entry_commands_activate(), and parse_key().