summaryrefslogtreecommitdiff
path: root/src/kbd-custom.h
blob: 0a0993c624b5d6e5e99d77a09217923e7b5d8568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
/* kbd-custom.h
   Header files for customizing keyboard configuration
   
   For Denemo, the GNU graphical music notation package
   (c) 2000-2005 Olivier Vermersch, Matthew Hiller */

#ifndef KBD_CUSTOM_H
#define KBD_CUSTOM_H

#include <stdio.h>
#include <limits.h>
#include <gdk/gdk.h>
#include <denemo/denemo.h>

#define MASK_FILTER(state) state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK \
				    | GDK_MOD1_MASK)

typedef struct _keyboard_dialog_data
{
  GtkButton *addbutton;
  GtkButton *add2button;
  GtkButton *delbutton;
  GtkButton *lookbutton;
  GtkStatusbar *statusbar;
  guint context_id;
  GtkTreeView *command_view;
  GtkTreeView *binding_view;
  GtkTextView *text_view;
  gulong handler_key_press;
  gulong handler_focus_out;
  gint command_idx;
  gint two_key;// 0 means not two key, 1 means first key, 2 second.
  gint first_keyval;
  gint first_modifiers;
} keyboard_dialog_data;

guint
dnm_sanitize_key_event(GdkEventKey *event);
guint
dnm_hyper_sanitize_key_event(GdkEventKey *event);
guint
dnm_meta_sanitize_key_state(GdkEventKey *event);
gboolean
isModifier(GdkEventKey *event);

//adapted from gtk because we want to allow uppercase accelerator through
//A, instead of <Shift>a
//we need this to be consistent with other modified values.
void dnm_accelerator_parse(const gchar *accelerator,
		guint *accelerator_key,
		GdkModifierType *accelerator_mods);

gchar *dnm_accelerator_name(guint accelerator_key,
		GdkModifierType accelerator_mods);

/**
 * List of all categories.
 * This list also defines the order of the
 *  categories in the keyboard shortcut dialog.
 */
extern gchar* kbd_categories[];
extern gint kbd_categories_length;

void
configure_keyboard (gpointer callback_data, guint callback_action,
		    GtkWidget *widget);

keymap *
allocate_keymap (void);

void
free_keymap(keymap *the_keymap);

void
register_command(keymap *the_keymap, GtkAction *action, const gchar *name, const gchar *label, const gchar *tooltip, gpointer callback);

void
alphabeticalize_commands(keymap *the_keymap);

//keymap *
//create_keymap (const gchar *filename);



void
keymap_clear_bindings (keymap *the_keymap);

guint
keymap_size (keymap *the_keymap);

void
keymap_foreach_command_binding (keymap *the_keymap, guint command_idx,
		GFunc func, gpointer user_data);

//-1 if the binding is not found
gint
lookup_command_for_keybinding (keymap *the_keymap, gint keyval, GdkModifierType state);

//-1 if the binding is not found
gint lookup_command_for_keyevent(GdkEventKey * event);

//-1 if the binding is not found
gint
lookup_command_for_keybinding_name (keymap *the_keymap, const gchar *binding_name);


gint 
lookup_command_from_name (keymap * keymap, const gchar *command_name);

const gchar *
lookup_name_from_idx(keymap *keymap, guint command_idx);

const gchar *
lookup_label_from_idx(keymap *keymap, guint command_idx);

const gchar *
lookup_tooltip_from_idx(keymap *keymap, guint command_idx);

gboolean
lookup_hidden_from_idx (keymap * keymap, guint command_idx);

gpointer
lookup_callback_from_idx (keymap * keymap, guint command_idx);

void
remove_keybinding (keymap *the_keymap, gint keyval, GdkModifierType state);

void
remove_keybinding_from_name (keymap *the_keymap, const gchar *binding);

typedef enum {
	POS_FIRST = 0,
	POS_LAST
} ListPosition;

gint
add_keybinding_to_idx (keymap * the_keymap, gint keyval,
        GdkModifierType state, guint command_idx, ListPosition pos);
gint
add_keybinding_to_named_command (keymap *the_keymap, gint keyval,
        GdkModifierType state, const gchar *command_name, ListPosition pos);
gint
add_named_binding_to_idx (keymap * the_keymap, gchar *kb_name,
			  guint command_idx, ListPosition pos);
gint
keymap_update_accel(keymap *the_keymap, GtkAction *action, guint keyval,
		GdkModifierType modifiers);

gint
keymap_accel_quick_edit_snooper(GtkWidget *grab_widget, GdkEventKey *event);

GtkAction *
lookup_action_from_name(gchar *command_name);
#define action_of_name(a,b) lookup_action_from_name(b)
const GtkAction *
lookup_action_from_idx (keymap * keymap, guint command_idx);
gboolean
execute_callback_from_idx(keymap *the_keymap, guint command_idx);
gboolean
execute_callback_from_name(keymap *the_keymap, const gchar* command_name);

gboolean
idx_has_callback (keymap *the_keymap, guint command_idx);

void
dump_command_info(keymap *the_keymap, gint command_idx);
guint
dnm_sanitize_key_state(GdkEventKey *event);
void
load_keymap_dialog (GtkWidget *Widget);


void
load_default_keymap_file (void);

void
load_system_keymap_dialog (GtkWidget * widget);
void
save_keymap_dialog (GtkWidget *widget);
void
load_keymap_dialog_location (GtkWidget * widget, gchar *location);
void
save_default_keymap_file_wrapper (GtkAction *action, gpointer param);

void
save_default_keymap_file (void);

void
set_state(gint state, gchar **value);

GtkWidget *
keymap_get_command_view(keymap *the_keymap);

GtkWidget *
keymap_get_binding_view();

void
keymap_cleanup_command_view(keyboard_dialog_data *data);

gboolean
keymap_change_binding_view_on_command_selection(GtkTreeSelection *selection,
		GtkTreeModel *model,
		GtkTreePath *path,
		gboolean path_currently_selected,
		gpointer data);

void
update_accel_labels(keymap *the_keymap, guint command_idx);

gboolean
command_has_binding (guint command_idx);

gint add_keybinding_for_name(gchar *name, gchar *binding);
gint add_keybinding_for_command(gint idx,  gchar *binding);

#endif