int gKey::code() { if (!_valid) return 0; int code = _event.keyval; if (code >= GDK_a && code <= GDK_z) code += GDK_A - GDK_a; else if (code == GDK_Alt_R) code = GDK_Alt_L; else if (code == GDK_Control_R) code = GDK_Control_L; else if (code == GDK_Meta_R) code = GDK_Meta_L; else if (code == GDK_Shift_R) code = GDK_Shift_L; else { int unicode = gdk_keyval_to_unicode(code); if (unicode >= 32 && unicode < 127) code = unicode; } return code; }
String PlatformKeyboardEvent::singleCharacterString(unsigned val) { switch (val) { case GDK_ISO_Enter: case GDK_KP_Enter: case GDK_Return: return String("\r"); case GDK_BackSpace: return String("\x8"); case GDK_Tab: return String("\t"); default: gunichar c = gdk_keyval_to_unicode(val); glong nwc; gunichar2* uchar16 = g_ucs4_to_utf16(&c, 1, 0, &nwc, 0); String retVal; if (uchar16) retVal = String((UChar*)uchar16, nwc); else retVal = String(); g_free(uchar16); return retVal; } }
static gboolean key(GtkWidget *widget, GdkEventKey *event, gpointer data) { M6502 *mpu = (M6502 *) data; Strudel* mb = (Strudel *) mpu->ext; guint32 u = 0; gchar *s = NULL; s = gdk_keyval_name(event->keyval); u = gdk_keyval_to_unicode(event->keyval); g_print("Key press event: %s (%d)\n", s, u); if (u == 0) { if (strcmp(s, "BackSpace") == 0) u = 0x8; else if (strcmp(s, "Return") == 0) u = '\r'; } else if (event->state & GDK_CONTROL_MASK) { u %= 32; } if (u > 0 && u < 128) { if (u == 3) { g_print("Interrupt\n"); M6502_do(mpu, M6502_IRQ); } else if (mb->keyr - mb->keyw != 1) { mb->key[mb->keyw++] = u % 128; } } return TRUE; }
static void wxFillOtherKeyEventFields(wxKeyEvent& event, wxWindowGTK *win, GdkEventKey *gdk_event) { int x = 0; int y = 0; GdkModifierType state; if (gdk_event->window) gdk_window_get_pointer(gdk_event->window, &x, &y, &state); event.SetTimestamp( gdk_event->time ); event.SetId(win->GetId()); event.m_shiftDown = (gdk_event->state & GDK_SHIFT_MASK) != 0; event.m_controlDown = (gdk_event->state & GDK_CONTROL_MASK) != 0; event.m_altDown = (gdk_event->state & GDK_MOD1_MASK) != 0; event.m_metaDown = (gdk_event->state & GDK_MOD2_MASK) != 0; event.m_scanCode = gdk_event->keyval; event.m_rawCode = (wxUint32) gdk_event->keyval; event.m_rawFlags = 0; #if wxUSE_UNICODE event.m_uniChar = gdk_keyval_to_unicode(gdk_event->keyval); #endif wxGetMousePosition( &x, &y ); win->ScreenToClient( &x, &y ); event.m_x = x; event.m_y = y; event.SetEventObject( win ); }
WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event) { WebKeyboardEvent result; result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time); result.modifiers = gdkStateToWebEventModifiers(normalizeEventState(event)); switch (event->type) { case GDK_KEY_RELEASE: result.type = WebInputEvent::KeyUp; break; case GDK_KEY_PRESS: result.type = WebInputEvent::RawKeyDown; break; default: ASSERT_NOT_REACHED(); } // According to MSDN: // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx // Key events with Alt modifier and F10 are system key events. // We just emulate this behavior. It's necessary to prevent webkit from // processing keypress event generated by alt-d, etc. // F10 is not special on Linux, so don't treat it as system key. if (result.modifiers & WebInputEvent::AltKey) result.isSystemKey = true; // The key code tells us which physical key was pressed (for example, the // A key went down or up). It does not determine whether A should be lower // or upper case. This is what text does, which should be the keyval. int windowsKeyCode = gdkEventToWindowsKeyCode(event); result.windowsKeyCode = WebKeyboardEvent::windowsKeyCodeWithoutLocation(windowsKeyCode); result.modifiers |= WebKeyboardEvent::locationModifiersFromWindowsKeyCode(windowsKeyCode); result.nativeKeyCode = event->hardware_keycode; if (result.windowsKeyCode == WebCore::VKEY_RETURN) // We need to treat the enter key as a key press of character \r. This // is apparently just how webkit handles it and what it expects. result.unmodifiedText[0] = '\r'; else // FIXME: fix for non BMP chars result.unmodifiedText[0] = static_cast<WebUChar>(gdk_keyval_to_unicode(event->keyval)); // If ctrl key is pressed down, then control character shall be input. if (result.modifiers & WebInputEvent::ControlKey) result.text[0] = getControlCharacter( result.windowsKeyCode, result.modifiers & WebInputEvent::ShiftKey); else result.text[0] = result.unmodifiedText[0]; result.setKeyIdentifierFromWindowsKeyCode(); // FIXME: Do we need to set IsAutoRepeat? if (isKeyPadKeyval(event->keyval)) result.modifiers |= WebInputEvent::IsKeyPad; return result; }
static gint cgraphics_textbox_keypress_handler( GtkWidget *widget, GdkEventKey *e, widget_t *w ) { int ucs4 = gdk_keyval_to_unicode(e->keyval); gchar * utf8 = g_ucs4_to_utf8(&ucs4, 1, NULL, NULL, NULL); int r = event_send( w, "key_down", "i", "key", (int)utf8[0] ); g_free(utf8); return r; }
static void set_key_event_string (GdkEventKey *event) { gunichar c = 0; if (event->keyval != GDK_KEY_VoidSymbol) c = gdk_keyval_to_unicode (event->keyval); if (c) { gchar buf[7]; gint len; gsize bytes_written; /* Apply the control key - Taken from Xlib */ if (event->state & GDK_CONTROL_MASK) { if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F; else if (c == '2') { event->string = g_memdup ("\0\0", 2); event->length = 1; buf[0] = '\0'; return; } else if (c >= '3' && c <= '7') c -= ('3' - '\033'); else if (c == '8') c = '\177'; else if (c == '/') c = '_' & 0x1F; } len = g_unichar_to_utf8 (c, buf); buf[len] = '\0'; event->string = g_locale_from_utf8 (buf, len, NULL, &bytes_written, NULL); if (event->string) event->length = bytes_written; } else if (event->keyval == GDK_KEY_Escape) { event->length = 1; event->string = g_strdup ("\033"); } else if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) { event->length = 1; event->string = g_strdup ("\r"); } if (!event->string) { event->length = 0; event->string = g_strdup (""); } }
const gchar *kp_to_str(KeyPress *kp) { static gchar *utf8 = NULL; gunichar key = gdk_keyval_to_unicode(kp->key); gint len; if (!utf8) utf8 = g_malloc0(MAX_CHAR_SIZE); len = g_unichar_to_utf8(key, utf8); utf8[len] = '\0'; return utf8; }
static gchar * snooper_parse_key(GdkEventKey *kevent) { gchar *tmpstr = NULL; const gchar *ctrl, *shift, *mod1; guint keyval; GdkModifierType consumed; gint modified; gdk_keymap_translate_keyboard_state (NULL, kevent->hardware_keycode, kevent->state, kevent->group, &keyval, NULL, NULL, &consumed); modified = kevent->state & ~consumed; ctrl = modified & GDK_CONTROL_MASK ? "c": ""; shift = modified & GDK_SHIFT_MASK ? "s": ""; mod1 = modified& GDK_MOD1_MASK ? "m": ""; modified &= (GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK); if (modified) { tmpstr = g_strdup_printf("<%s%s%s>%c", ctrl, shift, mod1, gdk_keyval_to_unicode(keyval)); }else{ tmpstr = g_strdup_printf("%c", gdk_keyval_to_unicode(keyval)); } DEBUG_MSG("snooper: key parsed = '%s'\n", tmpstr); return tmpstr; }
GdkEventKey * ide_gdk_synthesize_event_keyval (GdkWindow *window, guint keyval) { GdkDisplay *display; GdkDeviceManager *device_manager; GdkDevice *client_pointer; GdkEvent *ev; GdkKeymapKey *keys = NULL; gint n_keys = 0; gchar str[8] = { 0 }; gunichar ch; g_assert (window != NULL); g_assert (GDK_IS_WINDOW (window)); ch = gdk_keyval_to_unicode (keyval); g_unichar_to_utf8 (ch, str); ev = gdk_event_new (GDK_KEY_PRESS); ev->key.window = g_object_ref (window); ev->key.send_event = TRUE; ev->key.time = gtk_get_current_event_time (); ev->key.state = 0; ev->key.hardware_keycode = 0; ev->key.group = 0; ev->key.is_modifier = 0; ev->key.keyval = keyval; ev->key.string = g_strdup (str); ev->key.length = strlen (str); gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), ev->key.keyval, &keys, &n_keys); if (n_keys > 0) { ev->key.hardware_keycode = keys [0].keycode; ev->key.group = keys [0].group; if (keys [0].level == 1) ev->key.state |= GDK_SHIFT_MASK; g_free (keys); } display = gdk_window_get_display (ev->any.window); device_manager = gdk_display_get_device_manager (display); client_pointer = gdk_device_manager_get_client_pointer (device_manager); gdk_event_set_device (ev, gdk_device_get_associated_device (client_pointer)); return &ev->key; }
/* Class functions */ gboolean scim_bridge_client_imcontext_filter_key_event (GtkIMContext *context, GdkEventKey *event) { scim_bridge_pdebugln (8, "scim_bridge_client_imcontext_filter_key_event ()"); ScimBridgeClientIMContext *imcontext = SCIM_BRIDGE_CLIENT_IMCONTEXT (context); if (!(event->send_event & SEND_EVENT_MASK) && scim_bridge_client_is_messenger_opened () && imcontext != NULL && !key_snooper_used) { if (imcontext->client_window != NULL) { int new_window_x; int new_window_y; gdk_window_get_origin (imcontext->client_window, &new_window_x, &new_window_y); if (imcontext->window_x != new_window_x || imcontext->window_y != new_window_y) { imcontext->window_x = new_window_x; imcontext->window_y = new_window_y; scim_bridge_pdebugln (1, "The cursor location is changed: x = %d + %d\ty = %d + %d", imcontext->window_x, imcontext->cursor_x, imcontext->window_y, imcontext->cursor_y); if (set_cursor_location (imcontext, new_window_x, new_window_y, imcontext->cursor_x, imcontext->cursor_y)) { scim_bridge_perrorln ("An IOException occurred at scim_bridge_client_imcontext_filter_key_event ()"); return gtk_im_context_filter_keypress (fallback_imcontext, event); } } } boolean consumed = FALSE; if (filter_key_event (imcontext, event, &consumed)) { scim_bridge_perrorln ("An IOException occurred at scim_bridge_client_imcontext_filter_key_event ()"); } else if (consumed) { return TRUE; } } unsigned int accelerator_mask = (gtk_accelerator_get_default_mod_mask () & ~GDK_SHIFT_MASK); if (imcontext == NULL || !imcontext->enabled) { return gtk_im_context_filter_keypress (fallback_imcontext, event); } else if (event->type == GDK_KEY_PRESS && (event->state & accelerator_mask) == 0) { guint32 wchar = gdk_keyval_to_unicode (event->keyval); if (wchar != 0) { gchar buffer[10]; const int buffer_length = g_unichar_to_utf8 (wchar, buffer); buffer[buffer_length] = '\0'; g_signal_emit_by_name (focused_imcontext, "commit", &buffer); return TRUE; } }
void luaH_keystr_push(lua_State *L, guint keyval) { gchar ucs[7]; guint ulen; guint32 ukval = gdk_keyval_to_unicode(keyval); /* check for printable unicode character */ if (g_unichar_isgraph(ukval)) { ulen = g_unichar_to_utf8(ukval, ucs); ucs[ulen] = 0; lua_pushstring(L, ucs); } /* sent keysym for non-printable characters */ else lua_pushstring(L, gdk_keyval_name(keyval)); }
/* A key was pressed in locationbar */ static gboolean _interface_tweaks_on_key_press_event(GSignalInvocationHint *inHint, guint inNumberParams, const GValue *inParams, gpointer inUserData) { g_return_val_if_fail(GTK_IS_ENTRY(inUserData), FALSE); GtkEntry *entry=GTK_ENTRY(inUserData); GtkWidget *target; GdkEventKey *event; guint changedSignalID; GSList *handlers; /* Get target of this event and check if it is for locationbar entry */ target=GTK_WIDGET(g_value_get_object(inParams)); if(target==GTK_WIDGET(entry)) { /* Get key-event data */ inParams++; event=(GdkEventKey*)g_value_get_boxed(inParams); /* Check if key-event would _not_ add any characters */ if(!(gdk_keyval_is_upper(event->keyval)==gdk_keyval_is_lower(event->keyval) && gdk_unicode_to_keyval(gdk_keyval_to_unicode(event->keyval))!=event->keyval)) { /* Get "changed" signal ID */ changedSignalID=g_signal_lookup("changed", GTK_TYPE_ENTRY); /* Block all unblocked signal handlers for "changed" signal, remove selected * text region from entry text and unblock these signal handlers again. * This way we keep Midori's auto-completion working. Otherwise it fetches the * complete entry text with the text portion in selected text region and adds * the pressed key to it which results in a completely wrong text for auto-completion. */ handlers=_interface_tweaks_block_all_handlers(G_OBJECT(entry), changedSignalID); gtk_editable_delete_selection(GTK_EDITABLE(entry)); _interface_tweaks_unblock_handlers(G_OBJECT(entry), handlers); g_slist_free(handlers); } } return(TRUE); }
/* This is an IBus workaround. The flow of events with IBus is that every time * it gets gets a key event, it: * * Sends it to the daemon via D-Bus asynchronously * When it gets an reply, synthesizes a new GdkEvent and puts it into the * GDK event queue with gdk_event_put(), including * IBUS_FORWARD_MASK = 1 << 25 in the state to prevent a loop. * * (Normally, IBus uses the GTK+ key snooper mechanism to get the key * events early, but since our key events aren't visible to GTK+ key snoopers, * IBus will instead get the events via the standard * GtkIMContext.filter_keypress() mechanism.) * * There are a number of potential problems here; probably the worst * problem is that IBus doesn't forward the timestamp with the event * so that every key event that gets delivered ends up with * GDK_CURRENT_TIME. This creates some very subtle bugs; for example * if you have IBus running and a keystroke is used to trigger * launching an application, focus stealing prevention won't work * right. http://code.google.com/p/ibus/issues/detail?id=1184 * * In any case, our normal flow of key events is: * * GDK filter function => clutter_x11_handle_event => clutter actor * * So, if we see a key event that gets delivered via the GDK event handler * function - then we know it must be one of these synthesized events, and * we should push it back to clutter. * * To summarize, the full key event flow with IBus is: * * GDK filter function * => Mutter * => gnome_cinnamon_plugin_xevent_filter() * => clutter_x11_handle_event() * => clutter event delivery to actor * => gtk_im_context_filter_event() * => sent to IBus daemon * => response received from IBus daemon * => gdk_event_put() * => GDK event handler * => <this function> * => clutter_event_put() * => clutter event delivery to actor * * Anything else we see here we just pass on to the normal GDK event handler * gtk_main_do_event(). */ static void gnome_cinnamon_gdk_event_handler (GdkEvent *event_gdk, gpointer data) { if (event_gdk->type == GDK_KEY_PRESS || event_gdk->type == GDK_KEY_RELEASE) { ClutterActor *stage; Window stage_xwindow; stage = clutter_stage_get_default (); stage_xwindow = clutter_x11_get_stage_window (CLUTTER_STAGE (stage)); if (GDK_WINDOW_XID (event_gdk->key.window) == stage_xwindow) { ClutterDeviceManager *device_manager = clutter_device_manager_get_default (); ClutterInputDevice *keyboard = clutter_device_manager_get_core_device (device_manager, CLUTTER_KEYBOARD_DEVICE); ClutterEvent *event_clutter = clutter_event_new ((event_gdk->type == GDK_KEY_PRESS) ? CLUTTER_KEY_PRESS : CLUTTER_KEY_RELEASE); event_clutter->key.time = event_gdk->key.time; event_clutter->key.flags = CLUTTER_EVENT_NONE; event_clutter->key.stage = CLUTTER_STAGE (stage); event_clutter->key.source = NULL; /* This depends on ClutterModifierType and GdkModifierType being * identical, which they are currently. (They both match the X * modifier state in the low 16-bits and have the same extensions.) */ event_clutter->key.modifier_state = event_gdk->key.state; event_clutter->key.keyval = event_gdk->key.keyval; event_clutter->key.hardware_keycode = event_gdk->key.hardware_keycode; event_clutter->key.unicode_value = gdk_keyval_to_unicode (event_clutter->key.keyval); event_clutter->key.device = keyboard; clutter_event_put (event_clutter); clutter_event_free (event_clutter); return; } } gtk_main_do_event (event_gdk); }
static gboolean no_sequence_matches (GtkIMContext *context, GdkEventKey *event) { gunichar uc; gchar buf[7]; uc = gdk_keyval_to_unicode (event->keyval); if (uc != 0) { buf[g_unichar_to_utf8 (uc, buf)] = '\0'; g_signal_emit_by_name (context, "commit", buf); g_signal_emit_by_name (context, "preedit-changed"); return TRUE; } else return FALSE; }
static gboolean dtmf_pressed(RingMainWindow *win, GdkEventKey *event, G_GNUC_UNUSED gpointer user_data) { g_return_val_if_fail(event->type == GDK_KEY_PRESS, GDK_EVENT_PROPAGATE); /* we want to react to digit key presses, as long as a GtkEntry is not the * input focus */ GtkWidget *focus = gtk_window_get_focus(GTK_WINDOW(win)); if (GTK_IS_ENTRY(focus)) return GDK_EVENT_PROPAGATE; /* make sure that a call is selected*/ QItemSelectionModel *selection = CallModel::instance().selectionModel(); QModelIndex idx = selection->currentIndex(); if (!idx.isValid()) return GDK_EVENT_PROPAGATE; /* make sure that the selected call is in progress */ Call *call = CallModel::instance().getCall(idx); Call::LifeCycleState state = call->lifeCycleState(); if (state != Call::LifeCycleState::PROGRESS) return GDK_EVENT_PROPAGATE; /* filter out cretain MOD masked key presses so that, for example, 'Ctrl+c' * does not result in a 'c' being played. * we filter Ctrl, Alt, and SUPER/HYPER/META keys */ if ( event->state & ( GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK )) return GDK_EVENT_PROPAGATE; /* pass the character that was entered to be played by the daemon; * the daemon will filter out invalid DTMF characters */ guint32 unicode_val = gdk_keyval_to_unicode(event->keyval); QString val = QString::fromUcs4(&unicode_val, 1); call->playDTMF(val); g_debug("attemptingto play DTMF tone during ongoing call: %s", val.toUtf8().constData()); /* always propogate the key, so we don't steal accelerators/shortcuts */ return GDK_EVENT_PROPAGATE; }
bool tmKey::uniToWxk(wxChar uniCode, int& wxk, int& mod) // static { #ifdef __WXMSW__ // Convert key to scan code const SHORT scancode = ::VkKeyScan(uniCode); const unsigned char vk = LOBYTE(scancode); // Low eight bits = virtual-key code const int state = HIBYTE(scancode); // The next eight bits = shift state if (state & 1) mod |= wxMOD_SHIFT; if (state & 2) mod |= wxMOD_CONTROL; if (state & 4) mod |= wxMOD_ALT; wxk = wxCharCodeMSWToWX(vk, 0); if (wxk == 0) { // Normal ascii char // Note that this is set to the virtual keycode (which does not necessarily // correspond to the ascii value). This is needed because keydown events // report it in this format. wxk = vk; } return true; #elif defined(__WXGTK__) guint keyval = gdk_unicode_to_keyval(uniCode); if (keyval & 0x01000000) return false; if (gdk_keyval_is_upper(keyval)) { mod |= wxMOD_SHIFT; keyval = gdk_keyval_to_lower(keyval); #ifdef __WXDEBUG__ wxLogDebug(wxT("uniToWxk(%x - %c) downshifting keycode is %x"), uniCode, uniCode, keyval); #endif //__WXDEBUG__ } // FIXME not too correct - this is wxChar not wxKeyCode wxk = gdk_keyval_to_unicode(keyval); #ifdef __WXDEBUG__ wxLogDebug(wxT("uniToWxk(%x - %c) to %x - %c"), uniCode, uniCode, wxk, wxk); #endif //__WXDEBUG__ return true; #else #error Unknown platform #endif }
static gboolean cb_keypress(GtkWidget *widget, GdkEvent *event, gTextArea *ctrl) { if (event->key.state & GDK_CONTROL_MASK) { int key = gdk_keyval_to_unicode(gdk_keyval_to_upper(event->key.keyval)); if (key == 'Z') { ctrl->undo(); return true; } else if (key == 'Y') { ctrl->redo(); return true; } else if (key == 'A') { ctrl->selectAll(); return true; } else if (key == 'C') { ctrl->copy(); return true; } else if (key == 'X') { ctrl->cut(); ctrl->ensureVisible(); return true; } else if (key == 'V') { ctrl->paste(); ctrl->ensureVisible(); return true; } } return false; }
/* util_keyval_to_char (guint keyval) return: char * (alloc) {{{*/ char * util_keyval_to_char(guint keyval, gboolean ignore_whitespace) { char *key = NULL; guint32 unichar; int length; if ( (unichar = gdk_keyval_to_unicode(keyval)) ) { if (ignore_whitespace && !g_unichar_isgraph(unichar)) return NULL; key = g_malloc0_n(6, sizeof(char)); if ( key && (length = g_unichar_to_utf8(unichar, key))) { memset(&key[length], '\0', 6-length); return key; } else g_free(key); } return NULL; }/*}}}*/
bool tmKey::wxkToUni(int wxk, bool shifted, wxChar& uniCode) // static { if (!wxIsprint(wxk)) return false; #ifdef __WXMSW__ // Convert key to scan code const SHORT scancode = ::VkKeyScan(wxk); const unsigned char vk = LOBYTE(scancode); // Low eight bits = virtual-key code // Get the char on the key for this keycode unsigned char key_state[256]; memset (key_state, 0, sizeof (key_state)); const int BUFFER_SIZE = 10; if (shifted) key_state[VK_SHIFT] = 0x80; TCHAR buf[BUFFER_SIZE] = { 0 }; if (::ToUnicode(vk, 0, key_state, buf, BUFFER_SIZE, 0) != 1) return false; uniCode = buf[0]; return true; #elif defined(__WXGTK__) // FIXME not too correct - this is wxKeyCode not wxChar guint keyval = gdk_unicode_to_keyval(wxk); if (keyval & 0x01000000) return false; keyval = shifted ? gdk_keyval_to_upper(keyval) : gdk_keyval_to_lower(keyval); uniCode = gdk_keyval_to_unicode(keyval); #ifdef __WXDEBUG__ wxLogDebug(wxT("wxkToUni(%x- %c,%d) to %x - %c"), wxk, wxk, shifted, uniCode, uniCode); #endif //__WXDEBUG__ return true; #else #error Unknown platform #endif }
static String singleCharacterString(guint val) { switch (val) { case GDK_ISO_Enter: case GDK_KP_Enter: case GDK_Return: return String("\r"); default: gunichar c = gdk_keyval_to_unicode(val); glong nwc; gunichar2* uchar16 = g_ucs4_to_utf16(&c, 1, 0, &nwc, 0); String retVal; if (uchar16) retVal = String((UChar*)uchar16, nwc); else retVal = String(); g_free(uchar16); return retVal; } }
gboolean gom_keyboard_evt_keyval_to_key_identifier (guint keyval, const char **key_identifier, GomKeyLocationCode *key_location) { static GOnce just_this = G_ONCE_INIT; KeyIdentifierCodes *codes; GHashTable *ht; ht = g_once (&just_this, keyval_to_key_identifier_once, NULL); codes = g_hash_table_lookup (ht, &keyval); if (!codes) { keyval = gdk_keyval_to_upper (keyval); codes = g_hash_table_lookup (ht, &keyval); if (!codes) { codes = g_new0 (KeyIdentifierCodes, 1); codes->standard = keyval; codes->id = g_strdup_printf ("U+%04x", gdk_keyval_to_unicode (keyval)); g_hash_table_insert (ht, &codes->standard, codes); } } if (keyval == codes->left) { *key_location = GOM_DOM_KEY_LOCATION_LEFT; } else if (keyval == codes->right) { *key_location = GOM_DOM_KEY_LOCATION_RIGHT; } else if (keyval == codes->numpad) { *key_location = GOM_DOM_KEY_LOCATION_NUMPAD; } else { *key_location = GOM_DOM_KEY_LOCATION_STANDARD; } *key_identifier = codes->id; return TRUE; }
/* Transform gdk key events to our own events */ void key_to_event(guint keyval, gint mode) { gchar ucs[7]; gint ulen; guint32 ukval = gdk_keyval_to_unicode(keyval); /* check for printable unicode char */ /* TODO: Pass the keyvals through a GtkIMContext so that * we also get combining chars right */ if(g_unichar_isgraph(ukval)) { ulen = g_unichar_to_utf8(ukval, ucs); ucs[ulen] = 0; send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE, ucs, NULL); } /* send keysym for non-printable chars */ else { send_event(mode == GDK_KEY_PRESS ? KEY_PRESS : KEY_RELEASE, gdk_keyval_name(keyval), NULL); } }
static gboolean display_key_press_cb(GtkWidget *widget, GdkEventKey *event, MathDisplay *display) { int state; guint32 c; guint new_keyval = 0; /* Treat keypad keys as numbers even when numlock is off */ switch(event->keyval) { case GDK_KEY_KP_Delete: /* Period without numlock */ new_keyval = GDK_KEY_KP_Decimal; break; case GDK_KEY_KP_Insert: new_keyval = GDK_KEY_0; break; case GDK_KEY_KP_End: new_keyval = GDK_KEY_1; break; case GDK_KEY_KP_Down: new_keyval = GDK_KEY_2; break; case GDK_KEY_KP_Page_Down: new_keyval = GDK_KEY_3; break; case GDK_KEY_KP_Left: new_keyval = GDK_KEY_4; break; case GDK_KEY_KP_Begin: /* This is apparently what "5" does when numlock is off. */ new_keyval = GDK_KEY_5; break; case GDK_KEY_KP_Right: new_keyval = GDK_KEY_6; break; case GDK_KEY_KP_Home: new_keyval = GDK_KEY_7; break; case GDK_KEY_KP_Up: new_keyval = GDK_KEY_8; break; case GDK_KEY_KP_Page_Up: new_keyval = GDK_KEY_9; break; } if (new_keyval) { gboolean result; GdkEvent *new_event; new_event = gdk_event_copy((GdkEvent *)event); ((GdkEventKey *)new_event)->keyval = new_keyval; g_signal_emit_by_name(widget, "key-press-event", new_event, &result); gdk_event_free(new_event); return result; } state = event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK); c = gdk_keyval_to_unicode(event->keyval); /* Solve on enter */ if (event->keyval == GDK_KEY_Return || event->keyval == GDK_KEY_KP_Enter) { math_equation_solve(display->priv->equation); return TRUE; } /* Clear on escape */ if ((event->keyval == GDK_KEY_Escape && state == 0) || (event->keyval == GDK_KEY_BackSpace && state == GDK_CONTROL_MASK) || (event->keyval == GDK_KEY_Delete && state == GDK_SHIFT_MASK)) { math_equation_clear(display->priv->equation); return TRUE; } /* Numeric keypad will often insert '.' regardless of locale */ if (event->keyval == GDK_KEY_KP_Decimal) { math_equation_insert_numeric_point(display->priv->equation); return TRUE; } /* Substitute */ if (state == 0) { if (c == '*') { math_equation_insert(display->priv->equation, "×"); return TRUE; } if (c == '/') { math_equation_insert(display->priv->equation, "÷"); return TRUE; } if (c == '-') { math_equation_insert_subtract(display->priv->equation); return TRUE; } } /* Shortcuts */ if (state == GDK_CONTROL_MASK) { switch(event->keyval) { case GDK_KEY_bracketleft: math_equation_insert(display->priv->equation, "⌈"); return TRUE; case GDK_KEY_bracketright: math_equation_insert(display->priv->equation, "⌉"); return TRUE; case GDK_KEY_e: math_equation_insert_exponent(display->priv->equation); return TRUE; case GDK_KEY_f: math_equation_factorize(display->priv->equation); return TRUE; case GDK_KEY_i: math_equation_insert(display->priv->equation, "⁻¹"); return TRUE; case GDK_KEY_p: math_equation_insert(display->priv->equation, "π"); return TRUE; case GDK_KEY_r: math_equation_insert(display->priv->equation, "√"); return TRUE; case GDK_KEY_u: math_equation_insert(display->priv->equation, "µ"); return TRUE; case GDK_KEY_minus: math_equation_insert(display->priv->equation, "⁻"); return TRUE; case GDK_KEY_apostrophe: math_equation_insert(display->priv->equation, "°"); return TRUE; } } if (state == GDK_MOD1_MASK) { switch(event->keyval) { case GDK_KEY_bracketleft: math_equation_insert(display->priv->equation, "⌊"); return TRUE; case GDK_KEY_bracketright: math_equation_insert(display->priv->equation, "⌋"); return TRUE; } } if (state == GDK_CONTROL_MASK || math_equation_get_number_mode(display->priv->equation) == SUPERSCRIPT) { switch(event->keyval) { case GDK_KEY_0: case GDK_KEY_KP_0: math_equation_insert(display->priv->equation, "⁰"); return TRUE; case GDK_KEY_1: case GDK_KEY_KP_1: math_equation_insert(display->priv->equation, "¹"); return TRUE; case GDK_KEY_2: case GDK_KEY_KP_2: math_equation_insert(display->priv->equation, "²"); return TRUE; case GDK_KEY_3: case GDK_KEY_KP_3: math_equation_insert(display->priv->equation, "³"); return TRUE; case GDK_KEY_4: case GDK_KEY_KP_4: math_equation_insert(display->priv->equation, "⁴"); return TRUE; case GDK_KEY_5: case GDK_KEY_KP_5: math_equation_insert(display->priv->equation, "⁵"); return TRUE; case GDK_KEY_6: case GDK_KEY_KP_6: math_equation_insert(display->priv->equation, "⁶"); return TRUE; case GDK_KEY_7: case GDK_KEY_KP_7: math_equation_insert(display->priv->equation, "⁷"); return TRUE; case GDK_KEY_8: case GDK_KEY_KP_8: math_equation_insert(display->priv->equation, "⁸"); return TRUE; case GDK_KEY_9: case GDK_KEY_KP_9: math_equation_insert(display->priv->equation, "⁹"); return TRUE; } } else if (state == GDK_MOD1_MASK || math_equation_get_number_mode(display->priv->equation) == SUBSCRIPT) { switch(event->keyval) { case GDK_KEY_0: case GDK_KEY_KP_0: math_equation_insert(display->priv->equation, "₀"); return TRUE; case GDK_KEY_1: case GDK_KEY_KP_1: math_equation_insert(display->priv->equation, "₁"); return TRUE; case GDK_KEY_2: case GDK_KEY_KP_2: math_equation_insert(display->priv->equation, "₂"); return TRUE; case GDK_KEY_3: case GDK_KEY_KP_3: math_equation_insert(display->priv->equation, "₃"); return TRUE; case GDK_KEY_4: case GDK_KEY_KP_4: math_equation_insert(display->priv->equation, "₄"); return TRUE; case GDK_KEY_5: case GDK_KEY_KP_5: math_equation_insert(display->priv->equation, "₅"); return TRUE; case GDK_KEY_6: case GDK_KEY_KP_6: math_equation_insert(display->priv->equation, "₆"); return TRUE; case GDK_KEY_7: case GDK_KEY_KP_7: math_equation_insert(display->priv->equation, "₇"); return TRUE; case GDK_KEY_8: case GDK_KEY_KP_8: math_equation_insert(display->priv->equation, "₈"); return TRUE; case GDK_KEY_9: case GDK_KEY_KP_9: math_equation_insert(display->priv->equation, "₉"); return TRUE; } } return FALSE; }
// FIXME: This is incomplete. We should change this to mirror // more like what Firefox does, and generate these switch statements // at build time. String PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(unsigned 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: case GDK_Print: 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_BackSpace: return "U+0008"; 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))); } }
int dt_control_key_pressed_override(guint key, guint state) { dt_control_accels_t *accels = &darktable.control->accels; // TODO: if darkroom mode // did a : vim-style command start? static GList *autocomplete = NULL; static char vimkey_input[256]; if(darktable.control->vimkey_cnt) { guchar unichar = gdk_keyval_to_unicode(key); if(key == GDK_KEY_Return) { if(!strcmp(darktable.control->vimkey, ":q")) { dt_control_quit(); } else { dt_bauhaus_vimkey_exec(darktable.control->vimkey); } darktable.control->vimkey[0] = 0; darktable.control->vimkey_cnt = 0; dt_control_log_ack_all(); g_list_free(autocomplete); autocomplete = NULL; } else if(key == GDK_KEY_Escape) { darktable.control->vimkey[0] = 0; darktable.control->vimkey_cnt = 0; dt_control_log_ack_all(); g_list_free(autocomplete); autocomplete = NULL; } else if(key == GDK_KEY_BackSpace) { darktable.control->vimkey_cnt -= (darktable.control->vimkey + darktable.control->vimkey_cnt) - g_utf8_prev_char(darktable.control->vimkey + darktable.control->vimkey_cnt); darktable.control->vimkey[darktable.control->vimkey_cnt] = 0; if(darktable.control->vimkey_cnt == 0) dt_control_log_ack_all(); else dt_control_log("%s", darktable.control->vimkey); g_list_free(autocomplete); autocomplete = NULL; } else if(key == GDK_KEY_Tab) { // TODO: also support :preset and :get? // auto complete: if(darktable.control->vimkey_cnt < 5) { snprintf(darktable.control->vimkey, sizeof(darktable.control->vimkey), ":set "); darktable.control->vimkey_cnt = 5; } else if(!autocomplete) { // TODO: handle '.'-separated things separately // this is a static list, and tab cycles through the list g_strlcpy(vimkey_input, darktable.control->vimkey + 5, sizeof(vimkey_input)); autocomplete = dt_bauhaus_vimkey_complete(darktable.control->vimkey + 5); autocomplete = g_list_append(autocomplete, vimkey_input); // remember input to cycle back } if(autocomplete) { // pop first. // the paths themselves are owned by bauhaus, // no free required. snprintf(darktable.control->vimkey, sizeof(darktable.control->vimkey), ":set %s", (char *)autocomplete->data); autocomplete = g_list_remove(autocomplete, autocomplete->data); darktable.control->vimkey_cnt = strlen(darktable.control->vimkey); } dt_control_log("%s", darktable.control->vimkey); } else if(g_unichar_isprint(unichar)) // printable unicode character { gchar utf8[6]; gint char_width = g_unichar_to_utf8(unichar, utf8); if(darktable.control->vimkey_cnt + 1 + char_width < 256) { g_utf8_strncpy(darktable.control->vimkey + darktable.control->vimkey_cnt, utf8, 1); darktable.control->vimkey_cnt += char_width; darktable.control->vimkey[darktable.control->vimkey_cnt] = 0; dt_control_log("%s", darktable.control->vimkey); g_list_free(autocomplete); autocomplete = NULL; } } else if(key == GDK_KEY_Up) { // TODO: step history up and copy to vimkey } else if(key == GDK_KEY_Down) { // TODO: step history down and copy to vimkey } return 1; } else if(key == ':' && darktable.control->key_accelerators_on) { darktable.control->vimkey[0] = ':'; darktable.control->vimkey[1] = 0; darktable.control->vimkey_cnt = 1; dt_control_log("%s", darktable.control->vimkey); return 1; } /* check if key accelerators are enabled*/ if(darktable.control->key_accelerators_on != 1) return 0; if(key == accels->global_sideborders.accel_key && state == accels->global_sideborders.accel_mods) { /* toggle panel viewstate */ dt_ui_toggle_panels_visibility(darktable.gui->ui); /* trigger invalidation of centerview to reprocess pipe */ dt_dev_invalidate(darktable.develop); gtk_widget_queue_draw(dt_ui_center(darktable.gui->ui)); return 1; } else if(key == accels->global_header.accel_key && state == accels->global_header.accel_mods) { char key[512]; const dt_view_t *cv = dt_view_manager_get_current_view(darktable.view_manager); /* do nothing if in collapse panel state TODO: reconsider adding this check to ui api */ g_snprintf(key, sizeof(key), "%s/ui/panel_collaps_state", cv->module_name); if(dt_conf_get_int(key)) return 0; /* toggle the header visibility state */ g_snprintf(key, sizeof(key), "%s/ui/show_header", cv->module_name); gboolean header = !dt_conf_get_bool(key); dt_conf_set_bool(key, header); /* show/hide the actual header panel */ dt_ui_panel_show(darktable.gui->ui, DT_UI_PANEL_TOP, header, TRUE); gtk_widget_queue_draw(dt_ui_center(darktable.gui->ui)); return 1; } return 0; }
bool WebPopupMenuProxyGtk::typeAheadFind(GdkEventKey* event) { // If we were given a non-printable character just skip it. gunichar unicodeCharacter = gdk_keyval_to_unicode(event->keyval); if (!g_unichar_isprint(unicodeCharacter)) { resetTypeAheadFindState(); return false; } glong charactersWritten; GUniquePtr<gunichar2> utf16String(g_ucs4_to_utf16(&unicodeCharacter, 1, nullptr, &charactersWritten, nullptr)); if (!utf16String) { resetTypeAheadFindState(); return false; } // If the character is the same as the last character, the user is probably trying to // cycle through the menulist entries. This matches the WebCore behavior for collapsed menulists. static const uint32_t searchTimeoutMs = 1000; bool repeatingCharacter = unicodeCharacter != m_previousKeyEventCharacter; if (event->time - m_previousKeyEventTimestamp > searchTimeoutMs) m_currentSearchString = String(reinterpret_cast<UChar*>(utf16String.get()), charactersWritten); else if (repeatingCharacter) m_currentSearchString.append(String(reinterpret_cast<UChar*>(utf16String.get()), charactersWritten)); m_previousKeyEventTimestamp = event->time; m_previousKeyEventCharacter = unicodeCharacter; GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_popup))); if (!children) return true; // We case fold before searching, because strncmp does not handle non-ASCII characters. GUniquePtr<gchar> searchStringWithCaseFolded(g_utf8_casefold(m_currentSearchString.utf8().data(), -1)); size_t prefixLength = strlen(searchStringWithCaseFolded.get()); // If a menu item has already been selected, start searching from the current // item down the list. This will make multiple key presses of the same character // advance the selection. GList* currentChild = children.get(); if (m_currentlySelectedMenuItem) { currentChild = g_list_find(children.get(), m_currentlySelectedMenuItem); if (!currentChild) { m_currentlySelectedMenuItem = nullptr; currentChild = children.get(); } // Repeating characters should iterate. if (repeatingCharacter) { if (GList* nextChild = g_list_next(currentChild)) currentChild = nextChild; } } GList* firstChild = currentChild; do { currentChild = g_list_next(currentChild); if (!currentChild) currentChild = children.get(); GUniquePtr<gchar> itemText(g_utf8_casefold(gtk_menu_item_get_label(GTK_MENU_ITEM(currentChild->data)), -1)); if (!strncmp(searchStringWithCaseFolded.get(), itemText.get(), prefixLength)) { gtk_menu_shell_select_item(GTK_MENU_SHELL(m_popup), GTK_WIDGET(currentChild->data)); break; } } while (currentChild != firstChild); return true; }
if (event->state == 0) v = rb_str_new2("\n"); else v = ID2SYM(rb_intern("enter")); } KEY_SYM(Escape, escape); else if (event->length > 0) { if ((event->state & GDK_CONTROL_MASK) || (event->state & GDK_MOD1_MASK)) { guint kv; gint len; gunichar ch; char chbuf[7] = {0}; ch = gdk_keyval_to_unicode(event->keyval); len = g_unichar_to_utf8(ch, chbuf); chbuf[len] = '\0'; v = ID2SYM(rb_intern(chbuf)); if (modifiers & GDK_SHIFT_MASK) modifiers ^= GDK_SHIFT_MASK; } else { if (event->string[0] == '\r' && event->length == 1) v = rb_str_new2("\n"); else v = rb_str_new(event->string, event->length); } } KEY_SYM(Insert, insert);
gboolean key_handle_key_press (GtkWidget *wid, GdkEventKey *evt, session *sess) { struct key_binding *kb; int n; GSList *list; /* where did this event come from? */ list = sess_list; while (list) { sess = list->data; if (sess->gui->input_box == wid) { if (sess->gui->is_tab) sess = current_tab; break; } list = list->next; } if (!list) return FALSE; current_sess = sess; if (plugin_emit_keypress (sess, evt->state, evt->keyval, gdk_keyval_to_unicode (evt->keyval))) return 1; /* maybe the plugin closed this tab? */ if (!is_session (sess)) return 1; list = keybind_list; while (list) { kb = (struct key_binding*)list->data; if (kb->keyval == evt->keyval && kb->mod == key_modifier_get_valid (evt->state)) { if (kb->action < 0 || kb->action > KEY_MAX_ACTIONS) return 0; /* Run the function */ n = key_actions[kb->action].handler (wid, evt, kb->data1, kb->data2, sess); switch (n) { case 0: return 1; case 2: g_signal_stop_emission_by_name (G_OBJECT (wid), "key_press_event"); return 1; } } list = g_slist_next (list); } switch (evt->keyval) { case GDK_KEY_space: key_action_tab_clean (); break; } return 0; }
int clip_GDK_KEYVALTOUNICODE(ClipMachine * ClipMachineMemory) { guint keyval = INT_OPTION(ClipMachineMemory, 1, 0); wchar_t wc; //= INT_OPTION(ClipMachineMemory, 1,0); gchar *result; int total_len, first, clen; wc = gdk_keyval_to_unicode(keyval); total_len = 0; if (wc < 0x80) total_len += 1; else if (wc < 0x800) total_len += 2; else if (wc < 0x10000) total_len += 3; else if (wc < 0x200000) total_len += 4; else if (wc < 0x4000000) total_len += 5; else total_len += 6; result = calloc(total_len + 1, sizeof(char)); if (wc < 0x80) { first = 0; clen = 1; } else if (wc < 0x800) { first = 0xc0; clen = 2; } else if (wc < 0x10000) { first = 0xe0; clen = 3; } else if (wc < 0x200000) { first = 0xf0; clen = 4; } else if (wc < 0x4000000) { first = 0xf8; clen = 5; } else { first = 0xfc; clen = 6; } switch (clen) { case 6: result[5] = (wc & 0x3f) | 0x80; wc >>= 6; /* Fall through */ case 5: result[4] = (wc & 0x3f) | 0x80; wc >>= 6; /* Fall through */ case 4: result[3] = (wc & 0x3f) | 0x80; wc >>= 6; /* Fall through */ case 3: result[2] = (wc & 0x3f) | 0x80; wc >>= 6; /* Fall through */ case 2: result[1] = (wc & 0x3f) | 0x80; wc >>= 6; /* Fall through */ case 1: result[0] = wc | first; } _clip_retc(ClipMachineMemory, result); free(result); return 0; }