From c23f33a8e2488223595210eaee6dea80739e654f Mon Sep 17 00:00:00 2001 From: dusanx Date: Mon, 27 Apr 2009 14:53:28 +0200 Subject: Key handling finished --- uzbl.c | 60 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 18 deletions(-) (limited to 'uzbl.c') diff --git a/uzbl.c b/uzbl.c index b237903..0562fac 100644 --- a/uzbl.c +++ b/uzbl.c @@ -29,7 +29,7 @@ */ -#define LENGTH(x) (sizeof x / sizeof x[0]) +#define LENGTH(x) (sizeof x / sizeof x[0]) #include #include @@ -68,7 +68,7 @@ static gboolean show_status = FALSE; static gboolean insert_mode = FALSE; static gboolean status_top = FALSE; static gchar* modkey = NULL; - +static guint modmask = 0; typedef struct { const char *binding; @@ -352,29 +352,33 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event) if (event->type != GDK_KEY_PRESS) return result; - //TURN OFF INSERT MODE - if (insert_mode && (event->keyval == GDK_Escape)) { - insert_mode = FALSE; + //TURN OFF/ON INSERT MODE + if (!always_insert_mode && ((insert_mode && (event->keyval == GDK_Escape)) || (!insert_mode && (event->string[0] == 'i')))) { + insert_mode = !insert_mode; update_title (GTK_WINDOW (main_window)); return TRUE; } - //TURN ON INSERT MODE - if (!insert_mode && (event->string[0] == 'i')) { - insert_mode = TRUE; - update_title (GTK_WINDOW (main_window)); - return TRUE; + //INTERNAL BINDINGS + for (i = 0; i < num_internal_bindings; i++) { + if (strcmp(event->string, internal_bindings[i].binding) == 0) { + if (!insert_mode || (event->state == modmask)) { + parse_command (internal_bindings[i].action); + result = TRUE; + } + } } - //INTERNAL KEYS - if (always_insert_mode || !insert_mode) { - for (i = 0; i < num_internal_bindings; i++) { - if (event->string[0] == internal_bindings[i].binding[0]) { - parse_command (internal_bindings[i].action); + //EXTERNAL BINDINGS + for (i = 0; i < num_external_bindings; i++) { + if (strcmp(event->string, external_bindings[i].binding) == 0) { + if (!insert_mode || (event->state == modmask)) { + run_command(external_bindings[i].action, NULL); result = TRUE; - } - } + } + } } + if (!result) result = (insert_mode ? FALSE : TRUE); @@ -504,8 +508,28 @@ settings_init () { if (modkey) { printf ("Modkey: %s\n", modkey); } else { - printf ("Modkey disabled\n"); + printf ("Modkey disabled\n"); + modkey = ""; } + //POSSIBLE MODKEY VALUES (COMBINATIONS CAN BE USED) + gchar* modkeyup = g_utf8_strup(modkey, -1); + if (g_strrstr(modkeyup,"SHIFT") != NULL) modmask |= GDK_SHIFT_MASK; //the Shift key. + if (g_strrstr(modkeyup,"LOCK") != NULL) modmask |= GDK_LOCK_MASK; //a Lock key (depending on the modifier mapping of the X server this may either be CapsLock or ShiftLock). + if (g_strrstr(modkeyup,"CONTROL") != NULL) modmask |= GDK_CONTROL_MASK; //the Control key. + if (g_strrstr(modkeyup,"MOD1") != NULL) modmask |= GDK_MOD1_MASK; //the fourth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier, but normally it is the Alt key). + if (g_strrstr(modkeyup,"MOD2") != NULL) modmask |= GDK_MOD2_MASK; //the fifth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"MOD3") != NULL) modmask |= GDK_MOD3_MASK; //the sixth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"MOD4") != NULL) modmask |= GDK_MOD4_MASK; //the seventh modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"MOD5") != NULL) modmask |= GDK_MOD5_MASK; //the eighth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier). + if (g_strrstr(modkeyup,"BUTTON1") != NULL) modmask |= GDK_BUTTON1_MASK; //the first mouse button. + if (g_strrstr(modkeyup,"BUTTON2") != NULL) modmask |= GDK_BUTTON2_MASK; //the second mouse button. + if (g_strrstr(modkeyup,"BUTTON3") != NULL) modmask |= GDK_BUTTON3_MASK; //the third mouse button. + if (g_strrstr(modkeyup,"BUTTON4") != NULL) modmask |= GDK_BUTTON4_MASK; //the fourth mouse button. + if (g_strrstr(modkeyup,"BUTTON5") != NULL) modmask |= GDK_BUTTON5_MASK; //the fifth mouse button. + if (g_strrstr(modkeyup,"SUPER") != NULL) modmask |= GDK_SUPER_MASK; //the Super modifier. Since 2.10 + if (g_strrstr(modkeyup,"HYPER") != NULL) modmask |= GDK_HYPER_MASK; //the Hyper modifier. Since 2.10 + if (g_strrstr(modkeyup,"META") != NULL) modmask |= GDK_META_MASK; //the Meta modifier. Since 2.10 */ + free (modkeyup); if (keysi) { int i = 0; -- cgit v1.2.3