// FIXME: This is incomplete. We should change this to mirror // more like what Firefox does, and generate these switch statements // at build time. static String keyIdentifierForGdkKeyCode(guint keyCode) { switch (keyCode) { case GDK_Menu: case GDK_Alt_L: case GDK_Alt_R: return "Alt"; case GDK_Clear: return "Clear"; case GDK_Down: return "Down"; // "End" case GDK_End: return "End"; // "Enter" case GDK_ISO_Enter: case GDK_KP_Enter: case GDK_Return: return "Enter"; case GDK_Execute: return "Execute"; case GDK_F1: return "F1"; case GDK_F2: return "F2"; case GDK_F3: return "F3"; case GDK_F4: return "F4"; case GDK_F5: return "F5"; case GDK_F6: return "F6"; case GDK_F7: return "F7"; case GDK_F8: return "F8"; case GDK_F9: return "F9"; case GDK_F10: return "F10"; case GDK_F11: return "F11"; case GDK_F12: return "F12"; case GDK_F13: return "F13"; case GDK_F14: return "F14"; case GDK_F15: return "F15"; case GDK_F16: return "F16"; case GDK_F17: return "F17"; case GDK_F18: return "F18"; case GDK_F19: return "F19"; case GDK_F20: return "F20"; case GDK_F21: return "F21"; case GDK_F22: return "F22"; case GDK_F23: return "F23"; case GDK_F24: return "F24"; case GDK_Help: return "Help"; case GDK_Home: return "Home"; case GDK_Insert: return "Insert"; case GDK_Left: return "Left"; case GDK_Page_Down: return "PageDown"; case GDK_Page_Up: return "PageUp"; case GDK_Pause: return "Pause"; case GDK_3270_PrintScreen: return "PrintScreen"; case GDK_Right: return "Right"; case GDK_Select: return "Select"; case GDK_Up: return "Up"; // Standard says that DEL becomes U+007F. case GDK_Delete: return "U+007F"; case GDK_ISO_Left_Tab: case GDK_3270_BackTab: case GDK_Tab: return "U+0009"; default: return String::format("U+%04X", gdk_keyval_to_unicode(gdk_keyval_to_upper(keyCode))); } }
gboolean onKeyPress(GtkWidget *widget, GdkEventKey *key, RuskWindow *rusk) { gboolean proceed = TRUE; char *script = g_strdup_printf( "onKeyPress({ctrlKey: %d, shiftKey: %d, superKey: %d, hyperKey: %d, metaKey: %d, string: '%s'})", (key->state & GDK_CONTROL_MASK)?1:0, (key->state & GDK_SHIFT_MASK)?1:0, (key->state & GDK_SUPER_MASK)?1:0, (key->state & GDK_HYPER_MASK)?1:0, (key->state & GDK_META_MASK)?1:0, gdk_keyval_name(key->keyval)); webkit_web_view_run_javascript(rusk->webview, script, NULL, NULL, NULL); g_free(script); if(key->state & GDK_CONTROL_MASK) { switch(gdk_keyval_to_upper(key->keyval)) { case GDK_KEY_S: inSiteSearchToggle(rusk); break; case GDK_KEY_N: if(key->state & GDK_SHIFT_MASK) { openURI(createNewWindow(rusk), HOMEPAGE); }else { inSiteSearchNext(rusk); } break; case GDK_KEY_P: if(key->state & GDK_SHIFT_MASK) { togglePrivateBrowsing(rusk); }else { inSiteSearchPrev(rusk); } break; case GDK_KEY_U: addressbarToggle(rusk); break; case GDK_KEY_G: globalSearchToggle(rusk, "google"); break; case GDK_KEY_M: globalSearchToggle(rusk, "maps"); break; case GDK_KEY_I: if(key->state & GDK_SHIFT_MASK) { toggleInspector(rusk); }else { globalSearchToggle(rusk, "images"); } break; default: proceed = FALSE; } }else { proceed = FALSE; } return proceed; }