Example #1
0
void on_key_press_event(GtkWidget *self, GdkEventKey *event, gpointer v)
{
    KeyGrabButton* b = KEYGRAB_BUTTON(v);
    guint key;
    GdkModifierType mods = event->state & gtk_accelerator_get_default_mod_mask();

    if ((event->keyval == FcitxKey_Escape
            || event->keyval == FcitxKey_Return) && !mods) {
        if (event->keyval == FcitxKey_Escape)
            g_signal_emit_by_name(G_OBJECT(b), "changed", b->key, b->mods);
        end_key_grab(b);
        keygrab_button_set_key(b, 0, 0);
        return;
    }

    key = gdk_keyval_to_upper(event->keyval);
    if (key == FcitxKey_ISO_Left_Tab)
        key = FcitxKey_Tab;

    if (gtk_accelerator_valid(key, mods)
            || (key == FcitxKey_Tab && mods)) {
        keygrab_button_set_key(b, key, mods);
        end_key_grab(b);
        b->key = key;
        b->mods = mods;
        g_signal_emit_by_name(G_OBJECT(b), "changed", b->key, b->mods);
        return;
    }

    keygrab_button_set_key(b, key, mods);
}
static void
sync_hotkey(KeyGrabButton* button, gpointer user_data)
{
    guint key1, key2;
    GdkModifierType mod1, mod2;
    keygrab_button_get_key(button, &key1, &mod1);
    keygrab_button_get_key(KEYGRAB_BUTTON(user_data), &key2, &mod2);

    if (key1 != key2 || mod1 != mod2)
        keygrab_button_set_key(KEYGRAB_BUTTON(user_data), key1, mod1);
}
Example #3
0
static void keygrab_button_init(KeyGrabButton *keygrabbutton)
{
    keygrab_button_set_key(keygrabbutton, 0, 0);
    gtk_widget_set_size_request(GTK_WIDGET(keygrabbutton), 100, -1);
    g_signal_connect(G_OBJECT(keygrabbutton), "clicked", (GCallback) begin_key_grab, NULL);
}
void sync_filter(FcitxGenericConfig* gconfig, FcitxConfigGroup *group, FcitxConfigOption *option, void *value, FcitxConfigSync sync, void *arg)
{
    FcitxConfigOptionDesc *codesc = option->optionDesc;
    if (!codesc)
        return;
    if (sync == Raw2Value) {
        switch (codesc->type) {
        case T_I18NString:
            break;
        case T_Integer: {
            int value = atoi(option->rawValue);
            gtk_spin_button_set_value(GTK_SPIN_BUTTON(arg), value);
        }
        break;
        case T_Color: {
            int r = 0, g = 0, b = 0;
            char scolor[9];
            sscanf(option->rawValue, "%d %d %d", &r, &g, &b);
            r = RoundColor(r);
            g = RoundColor(g);
            b = RoundColor(b);
            snprintf(scolor, 8 , "#%02X%02X%02X", r, g, b);
            GdkColor color;
            gdk_color_parse(scolor, &color);
            gtk_color_button_set_color(GTK_COLOR_BUTTON(arg), &color);
        }
        break;
        case T_Boolean: {
            gboolean bl;
            if (strcmp(option->rawValue, "True") == 0)
                bl = TRUE;
            else
                bl = FALSE;

            gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(arg), bl);
        }
        break;
        case T_Font: {
            gtk_font_button_set_font_name(GTK_FONT_BUTTON(arg), option->rawValue);
        }
        break;
        case T_Enum: {
            FcitxConfigEnum* cenum = &codesc->configEnum;
            int index = 0, i;
            for (i = 0; i < cenum->enumCount; i++) {
                if (strcmp(cenum->enumDesc[i], option->rawValue) == 0) {
                    index = i;
                }
            }
            gtk_combo_box_set_active(GTK_COMBO_BOX(arg), index);
        }
        break;
        case T_Hotkey: {
            FcitxHotkey hotkey[2];
            int j;
            FcitxHotkeySetKey(option->rawValue, hotkey);
            GArray *array = (GArray*) arg;

            for (j = 0; j < 2; j ++) {
                GtkWidget *button = g_array_index(array, GtkWidget*, j);
                keygrab_button_set_key(KEYGRAB_BUTTON(button), hotkey[j].sym, hotkey[j].state);
                if (hotkey[j].desc)
                    free(hotkey[j].desc);
            }
        }
        break;
        case T_File:
        case T_Char:
        case T_String: {
            gtk_entry_set_text(GTK_ENTRY(arg), option->rawValue);
        }
        break;
        }
    } else {
        if (codesc->type != T_I18NString && option->rawValue) {