Bool XkbDDXNamesFromRules( DeviceIntPtr keybd, char * rules_name, XkbRF_VarDefsPtr defs, XkbComponentNamesPtr names) { char buf[PATH_MAX]; FILE * file; Bool complete; XkbRF_RulesPtr rules; if (!rules_name) return FALSE; if (strlen(XkbBaseDirectory) + strlen(rules_name) + 8 > PATH_MAX) { LogMessage(X_ERROR, "XKB: Rules name is too long\n"); return FALSE; } sprintf(buf,"%s/rules/%s", XkbBaseDirectory, rules_name); file = fopen(buf, "r"); if (!file) { LogMessage(X_ERROR, "XKB: Couldn't open rules file %s\n", buf); return FALSE; } rules = XkbRF_Create(); if (!rules) { LogMessage(X_ERROR, "XKB: Couldn't create rules struct\n"); fclose(file); return FALSE; } if (!XkbRF_LoadRules(file, rules)) { LogMessage(X_ERROR, "XKB: Couldn't parse rules file %s\n", rules_name); fclose(file); XkbRF_Free(rules,TRUE); return FALSE; } memset(names, 0, sizeof(*names)); complete = XkbRF_GetComponents(rules,defs,names); fclose(file); XkbRF_Free(rules, TRUE); if (!complete) LogMessage(X_ERROR, "XKB: Rules returned no components\n"); return complete; }
Bool XkbDDXNamesFromRules( DeviceIntPtr keybd, char * rules_name, XkbRF_VarDefsPtr defs, XkbComponentNamesPtr names) { char buf[PATH_MAX]; FILE * file; Bool complete; XkbRF_RulesPtr rules; if (!rules_name) return False; if (XkbBaseDirectory==NULL) { if (strlen(rules_name)+7 > PATH_MAX) return False; sprintf(buf,"rules/%s",rules_name); } else { if (strlen(XkbBaseDirectory)+strlen(rules_name)+8 > PATH_MAX) return False; sprintf(buf,"%s/rules/%s",XkbBaseDirectory,rules_name); } if ((file= fopen(buf,"r"))==NULL) return False; if ((rules= XkbRF_Create(0,0))==NULL) { fclose(file); return False; } if (!XkbRF_LoadRules(file,rules)) { fclose(file); XkbRF_Free(rules,True); return False; } bzero((char *)names,sizeof(XkbComponentNamesRec)); complete= XkbRF_GetComponents(rules,defs,names); fclose(file); XkbRF_Free(rules,True); return complete; }
static void apply_keymap (MetaBackendX11 *x11) { MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11); XkbRF_RulesRec *xkb_rules; XkbRF_VarDefsRec xkb_var_defs = { 0 }; gchar *rules_file_path; if (!priv->keymap_layouts || !priv->keymap_variants || !priv->keymap_options) return; get_xkbrf_var_defs (priv->xdisplay, priv->keymap_layouts, priv->keymap_variants, priv->keymap_options, &rules_file_path, &xkb_var_defs); xkb_rules = XkbRF_Load (rules_file_path, NULL, True, True); if (xkb_rules) { XkbComponentNamesRec xkb_comp_names = { 0 }; XkbRF_GetComponents (xkb_rules, &xkb_var_defs, &xkb_comp_names); upload_xkb_description (priv->xdisplay, rules_file_path, &xkb_var_defs, &xkb_comp_names); free_xkb_component_names (&xkb_comp_names); XkbRF_Free (xkb_rules, True); } else { g_warning ("Couldn't load XKB rules"); } free_xkbrf_var_defs (&xkb_var_defs); g_free (rules_file_path); }
RulesInfo* X11Helper::loadRules(const TQString& file, bool layoutsOnly) { XkbRF_RulesPtr xkbRules = XkbRF_Load(TQFile::encodeName(file).data(), "", true, true); if (xkbRules == NULL) { // throw Exception return NULL; } RulesInfo* rulesInfo = new RulesInfo(); for (int i = 0; i < xkbRules->layouts.num_desc; ++i) { TQString layoutName(xkbRules->layouts.desc[i].name); rulesInfo->layouts.replace( layoutName, tqstrdup( xkbRules->layouts.desc[i].desc ) ); if( m_layoutsClean == true && layoutName.find( NON_CLEAN_LAYOUT_REGEXP ) != -1 && layoutName.endsWith("/jp") == false ) { kdDebug() << "Layouts are not clean (Xorg < 6.9.0 or XFree86)" << endl; m_layoutsClean = false; } } if( layoutsOnly == true ) { XkbRF_Free(xkbRules, true); return rulesInfo; } for (int i = 0; i < xkbRules->models.num_desc; ++i) rulesInfo->models.replace(xkbRules->models.desc[i].name, tqstrdup( xkbRules->models.desc[i].desc ) ); for (int i = 0; i < xkbRules->options.num_desc; ++i) rulesInfo->options.replace(xkbRules->options.desc[i].name, tqstrdup( xkbRules->options.desc[i].desc ) ); XkbRF_Free(xkbRules, true); // workaround for empty 'compose' options group description if( rulesInfo->options.find("compose:menu") && !rulesInfo->options.find("compose") ) { rulesInfo->options.replace("compose", "Compose Key Position"); } for(TQDictIterator<char> it(rulesInfo->options) ; it.current() != NULL; ++it ) { TQString option(it.currentKey()); int columnPos = option.find(":"); if( columnPos != -1 ) { TQString group = option.mid(0, columnPos); if( rulesInfo->options.find(group) == NULL ) { rulesInfo->options.replace(group, group.latin1()); kdDebug() << "Added missing option group: " << group << endl; } } } // // workaround for empty misc options group description in XFree86 4.4.0 // if( rulesInfo->options.find("numpad:microsoft") && !rulesInfo->options.find("misc") ) { // rulesInfo->options.replace("misc", "Miscellaneous compatibility options" ); // } return rulesInfo; }
int main(int argc, char **argv) { #ifdef HAVE_XKBRULES /* must be opened first */ fl_open_display(); /* only apply what was written in config */ if(argc > 1 && strcmp(argv[1], "--apply") == 0) { String layout; read_config(&layout); apply_changes_on_x(layout.c_str(), NULL); return 0; } else { read_config(NULL); } EDE_APPLICATION("ede-keyboard-conf"); String cl; dialog_canceled = false; /* get layout X holds */ fetch_current_layout(cl); /* construct GUI */ win = new AppWindow(340, 320, _("Keyboard configuration tool")); win->begin(); Fl_Tabs *tabs = new Fl_Tabs(10, 10, 320, 265); tabs->begin(); Fl_Group *layout_group = new Fl_Group(15, 30, 310, 240, _("Layout")); layout_group->begin(); layout_browser = new Fl_Hold_Browser(20, 40, 300, 190); /* so things can be nicely aligned per column */ int cwidths [] = {100, 0}; layout_browser->column_widths(cwidths); layout_browser->column_char('\t'); layout_group->resizable(layout_browser); show_flag = new Fl_Check_Button(20, 240, 300, 25, _("Show country flag")); show_flag->tooltip(_("Display country flag in panel keyboard applet")); show_flag->down_box(FL_DOWN_BOX); show_flag->value(show_flag_value); show_flag->callback(show_flag_cb); layout_group->end(); Fl_Group::current()->resizable(layout_group); Fl_Group *details_group = new Fl_Group(15, 30, 310, 240, _("Details")); details_group->hide(); details_group->begin(); repeat_press = new Fl_Check_Button(20, 45, 300, 25, _("Repeat pressed key")); repeat_press->tooltip(_("Allow pressed key to be repeated")); repeat_press->down_box(FL_DOWN_BOX); repeat_press->value(repeat_press_value); repeat_press->callback(repeat_press_cb); details_group->end(); tabs->end(); /* resizable box */ Fl_Box *rbox = new Fl_Box(30, 163, 65, 52); Fl_Group::current()->resizable(rbox); Fl_Button *ok_button = new Fl_Button(145, 285, 90, 25, _("&OK")); ok_button->callback(ok_cb); Fl_Button *cancel_button = new Fl_Button(240, 285, 90, 25, _("&Cancel")); cancel_button->callback(cancel_cb); win->end(); /* read all XKB layouts */ XkbRF_RulesPtr xkb_rules = fetch_all_layouts(cl); window_center_on_screen(win); win->show(argc, argv); Fl::run(); /* do not save configuration if was canceled */ if(!dialog_canceled && xkb_rules && layout_browser->value()) { int i = layout_browser->value(); /* get the layout that matches browser row */ char *n = xkb_rules->layouts.desc[i - 1].name; save_config(n); apply_changes_on_x(n, &cl); } if(xkb_rules) XkbRF_Free(xkb_rules, True); #else alert(_("ede-keyboard-conf was compiled without XKB extension. Please recompile it again")); #endif /* HAVE_XKBRULES */ return 0; }