コード例 #1
0
static void
cc_ua_panel_set_shortcut_label (CcUaPanel  *self,
				const char *label,
				const char *key)
{
	GtkWidget *widget;
	char *value;
	char *text;
	guint accel_key, *keycode;
	GdkModifierType mods;

	widget = WID (self->priv->builder, label);
	value = g_settings_get_string (self->priv->mediakeys_settings, key);

	if (value == NULL || *value == '\0') {
		gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
		g_free (value);
		return;
	}
	gtk_accelerator_parse_with_keycode (value, &accel_key, &keycode, &mods);
	if (accel_key == 0 && keycode == NULL && mods == 0) {
		gtk_label_set_text (GTK_LABEL (widget), _("No shortcut set"));
		g_free (value);
		g_warning ("Failed to parse keyboard shortcut: '%s'", value);
		return;
	}
	g_free (value);

	text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, mods);
	g_free (keycode);
	gtk_label_set_text (GTK_LABEL (widget), text);
	g_free (text);
}
コード例 #2
0
static void
update_shortcut_label (GtkWidget  *widget,
		       const char *value)
{
  char *text;
  guint accel_key, *keycode;
  GdkModifierType mods;

  if (value == NULL || *value == '\0')
    {
      gtk_label_set_text (GTK_LABEL (widget), "\342\200\224");
      return;
    }
  gtk_accelerator_parse_with_keycode (value, &accel_key, &keycode, &mods);
  if (accel_key == 0 && keycode == NULL && mods == 0)
    {
      gtk_label_set_text (GTK_LABEL (widget), "\342\200\224");
      g_warning ("Failed to parse keyboard shortcut: '%s'", value);
      return;
    }

  text = gtk_accelerator_get_label_with_keycode (gtk_widget_get_display (widget), accel_key, *keycode, mods);
  g_free (keycode);
  gtk_label_set_text (GTK_LABEL (widget), text);
  g_free (text);
}
コード例 #3
0
StdStrBuf C4KeyCodeEx::KeyCode2String(C4KeyCode wCode, bool fHumanReadable, bool fShort)
{
    // Gamepad keys
    if (Key_IsGamepad(wCode))
    {
        int iGamepad = Key_GetGamepad(wCode);
        int gamepad_event = Key_GetGamepadEvent(wCode);
        switch (gamepad_event)
        {
        case KEY_JOY_Left:
            return FormatString("Joy%dLeft", iGamepad+1);
        case KEY_JOY_Up:
            return FormatString("Joy%dUp", iGamepad+1);
        case KEY_JOY_Down:
            return FormatString("Joy%dDown", iGamepad+1);
        case KEY_JOY_Right:
            return FormatString("Joy%dRight", iGamepad+1);
        default:
            if (Key_IsGamepadAxis(wCode))
            {
                if (fHumanReadable)
                    // This is still not great, but it is not really possible to assign unknown axes to "left/right" "up/down"...
                    return FormatString("[%d] %s", int(1 + Key_GetGamepadAxisIndex(wCode)), Key_IsGamepadAxisHigh(wCode) ? "Max" : "Min");
                else
                    return FormatString("Joy%dAxis%d%s", iGamepad+1, static_cast<int>(Key_GetGamepadAxisIndex(wCode)+1), Key_IsGamepadAxisHigh(wCode) ? "Max" : "Min");
            }
            else
            {
                // button
                if (fHumanReadable)
                    // If there should be gamepads around with A B C D... on the buttons, we might create a display option to show letters instead...
                    return FormatString("< %d >", int(1 + Key_GetGamepadButtonIndex(wCode)));
                else
                    return FormatString("Joy%d%c", iGamepad+1, static_cast<char>(Key_GetGamepadButtonIndex(wCode) + 'A'));
            }
        }
    }
    // Mouse keys
    if (Key_IsMouse(wCode))
    {
        int mouse_id = Key_GetMouse(wCode);
        int mouse_event = Key_GetMouseEvent(wCode);
        const char *mouse_str = "Mouse";
        switch (mouse_event)
        {
        case KEY_MOUSE_Move:
            return FormatString("%s%dMove", mouse_str, mouse_id);
        case KEY_MOUSE_Wheel1Up:
            return FormatString("%s%dWheel1Up", mouse_str, mouse_id);
        case KEY_MOUSE_Wheel1Down:
            return FormatString("%s%dWheel1Down", mouse_str, mouse_id);
        case KEY_MOUSE_ButtonLeft:
            return FormatString("%s%dLeft", mouse_str, mouse_id);
        case KEY_MOUSE_ButtonRight:
            return FormatString("%s%dRight", mouse_str, mouse_id);
        case KEY_MOUSE_ButtonMiddle:
            return FormatString("%s%dMiddle", mouse_str, mouse_id);
        case KEY_MOUSE_ButtonLeftDouble:
            return FormatString("%s%dLeftDouble", mouse_str, mouse_id);
        case KEY_MOUSE_ButtonRightDouble:
            return FormatString("%s%dRightDouble", mouse_str, mouse_id);
        case KEY_MOUSE_ButtonMiddleDouble:
            return FormatString("%s%dMiddleDouble", mouse_str, mouse_id);
        default:
            // extended mouse button
        {
            uint8_t btn = Key_GetMouseEvent(wCode);
            if (btn >= KEY_MOUSE_Button1Double)
                return FormatString("%s%dButton%dDouble", mouse_str, mouse_id, int(btn-KEY_MOUSE_Button1Double));
            else
                return FormatString("%s%dButton%d", mouse_str, mouse_id, int(btn-KEY_MOUSE_Button1));
        }
        }
    }

    // it's a keyboard key
    if (!fHumanReadable) {
        // for config files and such: dump scancode
        return FormatString("$%x", static_cast<unsigned int>(wCode));
    }
#if defined(USE_WIN32_WINDOWS) || (defined(_WIN32) && defined(USE_GTK))

    // Query map
    const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
    while (pCheck->szName)
        if (wCode == pCheck->wCode) return StdStrBuf((pCheck->szShortName && fShort) ? pCheck->szShortName : pCheck->szName);
        else ++pCheck;

//  TODO: Works?
//  StdStrBuf Name; Name.SetLength(1000);
//  int res = GetKeyNameText(wCode, Name.getMData(), Name.getSize());
//  if(!res)
//    // not found: Compose as direct code
//    return FormatString("\\x%x", (DWORD) wCode);
//  // Set size
//  Name.SetLength(res);
//  return Name;

    wchar_t buf[100];
    int len = GetKeyNameText(wCode<<16, buf, 100);
    if (len > 0) {
        // buf is nullterminated name
        return StdStrBuf(buf);
    }
#elif defined (USE_COCOA)
    // query map
    const C4KeyCodeMapEntry *pCheck = KeyCodeMap;
    while (pCheck->szName)
        if (wCode == pCheck->wCode) return StdStrBuf((pCheck->szShortName && fShort) ? pCheck->szShortName : pCheck->szName);
        else ++pCheck;
    // not found: Compose as direct code
    return FormatString("\\x%x", static_cast<unsigned int>(wCode));
#elif defined(USE_GTK)
    Display * const dpy = gdk_x11_display_get_xdisplay(gdk_display_get_default());
    KeySym keysym = (KeySym)XkbKeycodeToKeysym(dpy,wCode+8,0,0);
    char* name = NULL;
    if (keysym != NoSymbol) { // is the keycode without shift modifiers mapped to a symbol?
        name = gtk_accelerator_get_label_with_keycode(gdk_display_get_default(), keysym, wCode+8, (GdkModifierType)0);
    }
    if (name) { // is there a string representation of the keysym?
        // prevent memleak
        StdStrBuf buf;
        buf.Copy(name);
        g_free(name);
        return buf;
    }
#elif defined(USE_SDL_MAINLOOP)
    StdStrBuf buf;
    buf.Copy(SDL_GetScancodeName(static_cast<SDL_Scancode>(wCode)));
    if (!buf.getLength()) buf.Format("\\x%x", wCode);
    return buf;
#endif
    return FormatString("$%x", static_cast<unsigned int>(wCode));
}