Crossfire Client, Trunk
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 "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

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

Bind Log

EndOf KList Enum

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

key_entry struct

EndOf Bind Log

A keybinding hash record structure.

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

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)

Don't care about modifiers

Definition at line 147 of file keys.c.

◆ KEYF_EDIT

#define KEYF_EDIT   (1 << 5)

Enter command mode

Definition at line 148 of file keys.c.

◆ KEYF_MOD_ALT

#define KEYF_MOD_ALT   (1 << 2)

For ALT key modifier

Definition at line 140 of file keys.c.

◆ KEYF_MOD_CTRL

#define KEYF_MOD_CTRL   (1 << 1)

Used in run mode

Definition at line 139 of file keys.c.

◆ KEYF_MOD_MASK

#define KEYF_MOD_MASK
Value:
KEYF_MOD_CTRL | \
KEYF_MOD_ALT | \
KEYF_MOD_META)

Definition at line 142 of file keys.c.

◆ KEYF_MOD_META

#define KEYF_MOD_META   (1 << 3)

For Meta key modifier

Definition at line 141 of file keys.c.

◆ KEYF_MOD_SHIFT

#define KEYF_MOD_SHIFT   (1 << 0)

Used in fire mode

Definition at line 138 of file keys.c.

◆ KEYF_R_CHAR

#define KEYF_R_CHAR   (1 << 7)

Character specific

Definition at line 152 of file keys.c.

◆ KEYF_R_GLOBAL

#define KEYF_R_GLOBAL   (1 << 6)

Save at user's file

Definition at line 151 of file keys.c.

◆ KEYHASH

#define KEYHASH   257

Definition at line 156 of file keys.c.

◆ MAX_COMMAND_LEN

#define MAX_COMMAND_LEN   256

Definition at line 86 of file keys.c.

◆ MAX_HISTORY

#define MAX_HISTORY   50

Definition at line 85 of file keys.c.

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 73 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 123 of file keys.c.

Referenced by bind_key(), and configure_keys().

◆ bind_keysym

guint32 * bind_keysym
static

Definition at line 119 of file keys.c.

Referenced by bind_key(), and configure_keys().

◆ cancelkeysym

guint32 cancelkeysym
static

Definition at line 121 of file keys.c.

Referenced by keybindings_init(), and keyfunc().

◆ commandkeysym

guint32 commandkeysym
static

Definition at line 119 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 89 of file keys.c.

Referenced by gtk_command_history(), and on_entry_commands_activate().

◆ directions

const char* const directions[9]

256-length array to keep track of when commands were sent to the server Array for direction strings for each numeric direction.

Definition at line 41 of file player.c.

Referenced by command_to_direction(), dir_to_command(), and keybind_insert().

◆ entry_commands

GtkWidget* entry_commands

◆ fire_label

GtkWidget* fire_label
static

Definition at line 49 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 87 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 57 of file keys.c.

Referenced by keys_init().

◆ keybinding_button_remove

GtkWidget * keybinding_button_remove
static

Definition at line 56 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 56 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 59 of file keys.c.

Referenced by keys_init(), and update_keybinding_list().

◆ keybinding_treeview

GtkWidget * keybinding_treeview
static

Definition at line 55 of file keys.c.

Referenced by keys_init().

◆ keybinding_window

GtkWidget * keybinding_window
static

◆ keys_char

◆ 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 166 of file keys.c.

Referenced by keybind_find(), keybind_insert(), keybind_remove(), keybindings_init(), keys_init(), save_keys(), show_keys(), toggle_keybind_scope(), unbind_key(), and update_keybinding_list().

◆ 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 49 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 89 of file keys.c.

Referenced by gtk_command_history(), and on_entry_commands_activate().

◆ spinbutton_count

GtkWidget* spinbutton_count

Definition at line 62 of file keys.c.

Referenced by keys_init(), list_item_drop(), and parse_key().

KEYF_MOD_SHIFT
#define KEYF_MOD_SHIFT
Definition: keys.c:138