static GSList* keys = NULL;
static GString* modkeys = NULL;
+static GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval);
static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* event);
void keybind_add(int mode, guint modkey, guint modmask, guint keyval, const gchar* command)
{
- struct _keybind_key* keybind = g_new0(struct _keybind_key, 1);
+ Keybind* keybind = g_new0(Keybind, 1);
keybind->mode = mode;
keybind->modkey = modkey;
}
}
+void keybind_remove(int mode, guint modkey, guint modmask, guint keyval)
+{
+ GSList* link = keybind_find(mode, modkey, modmask, keyval);
+ if (link) {
+ keys = g_slist_delete_link(keys, link);
+ }
+ /* TODO remove eventually no more used modkeys */
+}
+
+GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval)
+{
+ GSList* link;
+ for (link = keys; link != NULL; link = link->next) {
+ Keybind* keybind = (Keybind*)link->data;
+
+ if (keybind->mode == mode
+ && keybind->modmask == modmask
+ && keybind->modkey == modkey
+ && keybind->keyval == keyval) {
+ return link;
+ }
+ }
+
+ return NULL;
+}
+
static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* event)
{
- GSList* tmp;
GdkModifierType irrelevant;
guint keyval;
static GdkKeymap *keymap;
}
}
}
- /* TODO move to own function */
+
/* check for keybinding */
- for (tmp = keys; tmp != NULL; tmp = tmp->next) {
- struct _keybind_key* keybind = (struct _keybind_key*)tmp->data;
+ GSList* link = keybind_find(vp.state.mode, vp.state.modkey,
+ (CLEAN(event->state) & ~irrelevant), keyval);
- /* handle key presses */
- if (keybind->mode == vp.state.mode
- && keybind->modmask == (CLEAN(event->state) & ~irrelevant)
- && keybind->modkey == vp.state.modkey
- && keybind->keyval == keyval
- && keybind->command) {
- command_run(keybind->command);
+ if (link) {
+ Keybind* keybind = (Keybind*)link->data;
+ command_run(keybind->command);
- /* if key binding used, remove the modkey */
- vp.state.modkey = vp.state.count = 0;
- vp_update_statusbar();
+ /* if key binding used, remove the modkey */
+ vp.state.modkey = vp.state.count = 0;
+ vp_update_statusbar();
- return TRUE;
- }
+ return TRUE;
}
return FALSE;
#define IS_ESCAPE(event) (IS_ESCAPE_KEY(CLEAN(event->state), event->keyval))
#define IS_ESCAPE_KEY(s, k) ((s == 0 && k == GDK_Escape) || (s == GDK_CONTROL_MASK && k == GDK_c))
-struct _keybind_key {
+typedef struct {
int mode; /* mode maks for allowed browser modes */
guint modkey;
guint modmask; /* modemask for the kayval */
guint keyval;
gchar* command; /* command to run */
-};
+} Keybind;
void keybind_init(void);
void keybind_add(int mode, guint modkey, guint modmask, guint keyval, const gchar* command);
+void keybind_remove(int mode, guint modkey, guint modmask, guint keyval);
#endif /* end of include guard: KEYBIND_H */
g_free(u);
/* change state to normal mode */
- vp.state.mode = VP_MODE_NORMAL;
- vp_update_statusbar();
+ Arg a = {VP_MODE_NORMAL};
+ vp_set_mode(&a);
return TRUE;
}
/* initialize the keybindings */
keybind_init();
+ /* TODO read the key bindings from config file */
keybind_add(VP_MODE_NORMAL, GDK_g, 0, GDK_f, "source");
keybind_add(VP_MODE_NORMAL, 0, 0, GDK_colon, "input");
keybind_add(VP_MODE_NORMAL, 0, 0, GDK_d, "quit");