diff options
Diffstat (limited to 'libxklavier/xklavier_config_xkb.c')
-rw-r--r-- | libxklavier/xklavier_config_xkb.c | 785 |
1 files changed, 437 insertions, 348 deletions
diff --git a/libxklavier/xklavier_config_xkb.c b/libxklavier/xklavier_config_xkb.c index 05843fe..39b74e8 100644 --- a/libxklavier/xklavier_config_xkb.c +++ b/libxklavier/xklavier_config_xkb.c @@ -1,6 +1,6 @@ #include <errno.h> -#include <string.h> #include <locale.h> +#include <string.h> #include <unistd.h> #include <sys/stat.h> #include <sys/param.h> @@ -30,415 +30,504 @@ #include <X11/keysymdef.h> #ifdef XKB_HEADERS_PRESENT -static XkbRF_RulesPtr _xklRules; +static XkbRF_RulesPtr xkl_rules; -static XkbRF_RulesPtr _XklLoadRulesSet( void ) +static XkbRF_RulesPtr +xkl_rules_set_load(XklEngine * engine) { - XkbRF_RulesPtr rulesSet = NULL; - char fileName[MAXPATHLEN] = ""; - char *rf = _XklGetRulesSetName( XKB_DEFAULT_RULESET ); - char *locale = NULL; - - if( rf == NULL ) - { - _xklLastErrorMsg = "Could not find the XKB rules set"; - return NULL; - } - - locale = setlocale( LC_ALL, NULL ); - - snprintf( fileName, sizeof fileName, XKB_BASE "/rules/%s", rf ); - XklDebug( 160, "Loading rules from [%s]\n", fileName ); - - rulesSet = XkbRF_Load( fileName, locale, True, True ); - - if( rulesSet == NULL ) - { - _xklLastErrorMsg = "Could not load rules"; - return NULL; - } - return rulesSet; + XkbRF_RulesPtr rules_set = NULL; + char file_name[MAXPATHLEN] = ""; + char *rf = + xkl_engine_get_ruleset_name(engine, XKB_DEFAULT_RULESET); + char *locale = NULL; + + if (rf == NULL) { + xkl_last_error_message = + "Could not find the XKB rules set"; + return NULL; + } + + locale = setlocale(LC_ALL, NULL); + + snprintf(file_name, sizeof file_name, XKB_BASE "/rules/%s", rf); + xkl_debug(160, "Loading rules from [%s]\n", file_name); + + rules_set = XkbRF_Load(file_name, locale, True, True); + + if (rules_set == NULL) { + xkl_last_error_message = "Could not load rules"; + return NULL; + } + return rules_set; } -static void _XklFreeRulesSet( void ) +static void +xkl_rules_set_free(void) { - if ( _xklRules ) - XkbRF_Free( _xklRules, True ); - _xklRules = NULL; + if (xkl_rules) + XkbRF_Free(xkl_rules, True); + xkl_rules = NULL; } #endif -void _XklXkbConfigInit( void ) +void +xkl_xkb_init_config_registry(XklConfigRegistry * config) { #ifdef XKB_HEADERS_PRESENT - XkbInitAtoms( NULL ); + XkbInitAtoms(NULL); #endif } -Bool _XklXkbConfigLoadRegistry( void ) +gboolean +xkl_xkb_load_config_registry(XklConfigRegistry * config) { - struct stat statBuf; - char fileName[MAXPATHLEN] = ""; - char* rf = _XklGetRulesSetName( XKB_DEFAULT_RULESET ); + struct stat stat_buf; + char file_name[MAXPATHLEN] = ""; + char *rf = + xkl_engine_get_ruleset_name(xkl_config_registry_get_engine + (config), + XKB_DEFAULT_RULESET); - if ( rf == NULL ) - return False; + if (rf == NULL) + return FALSE; - snprintf( fileName, sizeof fileName, XKB_BASE "/rules/%s.xml", rf ); + snprintf(file_name, sizeof file_name, XKB_BASE "/rules/%s.xml", + rf); - if( stat( fileName, &statBuf ) != 0 ) - { - strncpy( fileName, XML_CFG_FALLBACK_PATH, sizeof fileName ); - fileName[ MAXPATHLEN - 1 ] = '\0'; - } + if (stat(file_name, &stat_buf) != 0) { + g_strlcpy(file_name, XML_CFG_FALLBACK_PATH, + sizeof file_name); + } - return XklConfigLoadRegistryFromFile( fileName ); + return xkl_config_registry_load_from_file(config, file_name); } #ifdef XKB_HEADERS_PRESENT -Bool _XklXkbConfigPrepareNative( const XklConfigRecPtr data, XkbComponentNamesPtr componentNamesPtr ) +gboolean +xkl_xkb_config_native_prepare(XklEngine * engine, + const XklConfigRec * data, + XkbComponentNamesPtr component_names_ptr) { - XkbRF_VarDefsRec _xklVarDefs; - Bool gotComponents; - - memset( &_xklVarDefs, 0, sizeof( _xklVarDefs ) ); - - _xklRules = _XklLoadRulesSet(); - if( !_xklRules ) - { - return False; - } - - _xklVarDefs.model = ( char * ) data->model; - - if( data->layouts != NULL ) - _xklVarDefs.layout = _XklConfigRecMergeLayouts( data ); - - if( data->variants != NULL ) - _xklVarDefs.variant = _XklConfigRecMergeVariants( data ); - - if( data->options != NULL ) - _xklVarDefs.options = _XklConfigRecMergeOptions( data ); - - gotComponents = XkbRF_GetComponents( _xklRules, &_xklVarDefs, componentNamesPtr ); - - free( _xklVarDefs.layout ); - free( _xklVarDefs.variant ); - free( _xklVarDefs.options ); - - if( !gotComponents ) - { - _xklLastErrorMsg = "Could not translate rules into components"; - /* Just cleanup the stuff in case of failure */ - _XklXkbConfigCleanupNative( componentNamesPtr ); - - return False; - } - - if ( _xklDebugLevel >= 200 ) - { - XklDebug( 200, "keymap: %s\n", componentNamesPtr->keymap ); - XklDebug( 200, "keycodes: %s\n", componentNamesPtr->keycodes ); - XklDebug( 200, "compat: %s\n", componentNamesPtr->compat ); - XklDebug( 200, "types: %s\n", componentNamesPtr->types ); - XklDebug( 200, "symbols: %s\n", componentNamesPtr->symbols ); - XklDebug( 200, "geometry: %s\n", componentNamesPtr->geometry ); - } - return True; + XkbRF_VarDefsRec xkl_var_defs; + gboolean got_components; + + memset(&xkl_var_defs, 0, sizeof(xkl_var_defs)); + + xkl_rules = xkl_rules_set_load(engine); + if (!xkl_rules) { + return FALSE; + } + + xkl_var_defs.model = (char *) data->model; + + if (data->layouts != NULL) + xkl_var_defs.layout = xkl_config_rec_merge_layouts(data); + + if (data->variants != NULL) + xkl_var_defs.variant = xkl_config_rec_merge_variants(data); + + if (data->options != NULL) + xkl_var_defs.options = xkl_config_rec_merge_options(data); + + got_components = + XkbRF_GetComponents(xkl_rules, &xkl_var_defs, + component_names_ptr); + + g_free(xkl_var_defs.layout); + g_free(xkl_var_defs.variant); + g_free(xkl_var_defs.options); + + if (!got_components) { + xkl_last_error_message = + "Could not translate rules into components"; + /* Just cleanup the stuff in case of failure */ + xkl_xkb_config_native_cleanup(engine, component_names_ptr); + + return FALSE; + } + + if (xkl_debug_level >= 200) { + xkl_debug(200, "keymap: %s\n", + component_names_ptr->keymap); + xkl_debug(200, "keycodes: %s\n", + component_names_ptr->keycodes); + xkl_debug(200, "compat: %s\n", + component_names_ptr->compat); + xkl_debug(200, "types: %s\n", component_names_ptr->types); + xkl_debug(200, "symbols: %s\n", + component_names_ptr->symbols); + xkl_debug(200, "geometry: %s\n", + component_names_ptr->geometry); + } + return TRUE; } -void _XklXkbConfigCleanupNative( XkbComponentNamesPtr componentNamesPtr ) +void +xkl_xkb_config_native_cleanup(XklEngine * engine, + XkbComponentNamesPtr component_names_ptr) { - _XklFreeRulesSet(); - - free(componentNamesPtr->keymap); - free(componentNamesPtr->keycodes); - free(componentNamesPtr->compat); - free(componentNamesPtr->types); - free(componentNamesPtr->symbols); - free(componentNamesPtr->geometry); + xkl_rules_set_free(); + + g_free(component_names_ptr->keymap); + g_free(component_names_ptr->keycodes); + g_free(component_names_ptr->compat); + g_free(component_names_ptr->types); + g_free(component_names_ptr->symbols); + g_free(component_names_ptr->geometry); } -static XkbDescPtr _XklConfigGetKeyboard( XkbComponentNamesPtr componentNamesPtr, Bool activate ) +static XkbDescPtr +xkl_config_get_keyboard(XklEngine * engine, + XkbComponentNamesPtr component_names_ptr, + gboolean activate) { - XkbDescPtr xkb = NULL; + XkbDescPtr xkb = NULL; #if 0 - xkb = XkbGetKeyboardByName( _xklDpy, - XkbUseCoreKbd, - &componentNames, - XkbGBN_AllComponentsMask & - ( ~XkbGBN_GeometryMask ), - XkbGBN_AllComponentsMask & - ( ~XkbGBN_GeometryMask ), - activate ); + xkb = XkbGetKeyboardByName(_xklDpy, + XkbUseCoreKbd, + &componentNames, + XkbGBN_AllComponentsMask & + (~XkbGBN_GeometryMask), + XkbGBN_AllComponentsMask & + (~XkbGBN_GeometryMask), activate); #else - char xkmFN[L_tmpnam]; - char xkbFN[L_tmpnam]; - FILE* tmpxkm; - XkbFileInfo result; - int xkmloadres; - - if ( tmpnam( xkmFN ) != NULL && - tmpnam( xkbFN ) != NULL ) - { - pid_t cpid, pid; - int status = 0; - FILE *tmpxkb; - - XklDebug( 150, "tmp XKB/XKM file names: [%s]/[%s]\n", xkbFN, xkmFN ); - if( (tmpxkb = fopen( xkbFN, "w" )) != NULL ) - { - fprintf( tmpxkb, "xkb_keymap {\n" ); - fprintf( tmpxkb, " xkb_keycodes { include \"%s\" };\n", componentNamesPtr->keycodes ); - fprintf( tmpxkb, " xkb_types { include \"%s\" };\n", componentNamesPtr->types ); - fprintf( tmpxkb, " xkb_compat { include \"%s\" };\n", componentNamesPtr->compat ); - fprintf( tmpxkb, " xkb_symbols { include \"%s\" };\n", componentNamesPtr->symbols ); - fprintf( tmpxkb, " xkb_geometry { include \"%s\" };\n", componentNamesPtr->geometry ); - fprintf( tmpxkb, "};\n" ); - fclose( tmpxkb ); - - XklDebug( 150, "xkb_keymap {\n" - " xkb_keycodes { include \"%s\" };\n" - " xkb_types { include \"%s\" };\n" - " xkb_compat { include \"%s\" };\n" - " xkb_symbols { include \"%s\" };\n" - " xkb_geometry { include \"%s\" };\n};\n", - componentNamesPtr->keycodes, - componentNamesPtr->types, - componentNamesPtr->compat, - componentNamesPtr->symbols, - componentNamesPtr->geometry ); - - cpid=fork(); - switch( cpid ) - { - case -1: - XklDebug( 0, "Could not fork: %d\n", errno ); - break; - case 0: - /* child */ - XklDebug( 160, "Executing %s\n", XKBCOMP ); - XklDebug( 160, "%s %s %s %s %s %s %s\n", - XKBCOMP, XKBCOMP, "-I", "-I" XKB_BASE, "-xkm", xkbFN, xkmFN ); - execl( XKBCOMP, XKBCOMP, "-I", "-I" XKB_BASE, "-xkm", xkbFN, xkmFN, NULL ); - XklDebug( 0, "Could not exec %s: %d\n", XKBCOMP, errno ); - exit( 1 ); - default: - /* parent */ - pid = waitpid( cpid, &status, 0 ); - XklDebug( 150, "Return status of %d (well, started %d): %d\n", pid, cpid, status ); - memset( (char *)&result, 0, sizeof(result) ); - result.xkb = XkbAllocKeyboard(); - - if( Success == XkbChangeKbdDisplay( _xklDpy, &result ) ) - { - XklDebug( 150, "Hacked the kbddesc - set the display...\n" ); - if( (tmpxkm = fopen( xkmFN, "r" )) != NULL ) - { - xkmloadres = XkmReadFile( tmpxkm, XkmKeymapLegal, XkmKeymapLegal, &result); - XklDebug( 150, "Loaded %s output as XKM file, got %d (comparing to %d)\n", - XKBCOMP, (int)xkmloadres, (int)XkmKeymapLegal ); - if ( (int)xkmloadres != (int)XkmKeymapLegal ) - { - XklDebug( 150, "Loaded legal keymap\n" ); - if( activate ) - { - XklDebug( 150, "Activating it...\n" ); - if( XkbWriteToServer(&result) ) - { - XklDebug( 150, "Updating the keyboard...\n" ); - xkb = result.xkb; - } else - { - XklDebug( 0, "Could not write keyboard description to the server\n" ); - } - } else /* no activate, just load */ - xkb = result.xkb; - } else /* could not load properly */ - { - XklDebug( 0, "Could not load %s output as XKM file, got %d (asked %d)\n", - XKBCOMP, (int)xkmloadres, (int)XkmKeymapLegal ); - } - fclose( tmpxkm ); - XklDebug( 160, "Unlinking the temporary xkm file %s\n", xkmFN ); - if ( _xklDebugLevel < 500 ) /* don't remove on high debug levels! */ - { - if ( remove( xkmFN ) == -1 ) - XklDebug( 0, "Could not unlink the temporary xkm file %s: %d\n", - xkmFN, errno ); - } else - XklDebug( 500, "Well, not really - the debug level is too high: %d\n", _xklDebugLevel ); - } else /* could not open the file */ - { - XklDebug( 0, "Could not open the temporary xkm file %s\n", xkmFN ); - } - } else /* could not assign to display */ - { - XklDebug( 0, "Could not change the keyboard description to display\n" ); - } - if ( xkb == NULL ) - XkbFreeKeyboard( result.xkb, XkbAllComponentsMask, True ); - break; - } - XklDebug( 160, "Unlinking the temporary xkb file %s\n", xkbFN ); - if ( _xklDebugLevel < 500 ) /* don't remove on high debug levels! */ - { - if ( remove( xkbFN ) == -1 ) - XklDebug( 0, "Could not unlink the temporary xkb file %s: %d\n", - xkbFN, errno ); - } else - XklDebug( 500, "Well, not really - the debug level is too high: %d\n", _xklDebugLevel ); - } else /* could not open input tmp file */ - { - XklDebug( 0, "Could not open tmp XKB file [%s]: %d\n", xkbFN, errno ); - } - } else - { - XklDebug( 0, "Could not get tmp names\n" ); - } + char xkm_fn[L_tmpnam]; + char xkb_fn[L_tmpnam]; + FILE *tmpxkm; + XkbFileInfo result; + int xkmloadres; + + Display *display = xkl_engine_get_display(engine); + + if (tmpnam(xkm_fn) != NULL && tmpnam(xkb_fn) != NULL) { + pid_t cpid, pid; + int status = 0; + FILE *tmpxkb; + + xkl_debug(150, "tmp XKB/XKM file names: [%s]/[%s]\n", + xkb_fn, xkm_fn); + if ((tmpxkb = fopen(xkb_fn, "w")) != NULL) { + fprintf(tmpxkb, "xkb_keymap {\n"); + fprintf(tmpxkb, + " xkb_keycodes { include \"%s\" };\n", + component_names_ptr->keycodes); + fprintf(tmpxkb, + " xkb_types { include \"%s\" };\n", + component_names_ptr->types); + fprintf(tmpxkb, + " xkb_compat { include \"%s\" };\n", + component_names_ptr->compat); + fprintf(tmpxkb, + " xkb_symbols { include \"%s\" };\n", + component_names_ptr->symbols); + fprintf(tmpxkb, + " xkb_geometry { include \"%s\" };\n", + component_names_ptr->geometry); + fprintf(tmpxkb, "};\n"); + fclose(tmpxkb); + + xkl_debug(150, "xkb_keymap {\n" + " xkb_keycodes { include \"%s\" };\n" + " xkb_types { include \"%s\" };\n" + " xkb_compat { include \"%s\" };\n" + " xkb_symbols { include \"%s\" };\n" + " xkb_geometry { include \"%s\" };\n};\n", + component_names_ptr->keycodes, + component_names_ptr->types, + component_names_ptr->compat, + component_names_ptr->symbols, + component_names_ptr->geometry); + + cpid = fork(); + switch (cpid) { + case -1: + xkl_debug(0, "Could not fork: %d\n", + errno); + break; + case 0: + /* child */ + xkl_debug(160, "Executing %s\n", XKBCOMP); + xkl_debug(160, "%s %s %s %s %s %s %s\n", + XKBCOMP, XKBCOMP, "-I", + "-I" XKB_BASE, "-xkm", xkb_fn, + xkm_fn); + execl(XKBCOMP, XKBCOMP, "-I", + "-I" XKB_BASE, "-xkm", xkb_fn, + xkm_fn, NULL); + xkl_debug(0, "Could not exec %s: %d\n", + XKBCOMP, errno); + exit(1); + default: + /* parent */ + pid = waitpid(cpid, &status, 0); + xkl_debug(150, + "Return status of %d (well, started %d): %d\n", + pid, cpid, status); + memset((char *) &result, 0, + sizeof(result)); + result.xkb = XkbAllocKeyboard(); + + if (Success == + XkbChangeKbdDisplay(display, + &result)) { + xkl_debug(150, + "Hacked the kbddesc - set the display...\n"); + if ((tmpxkm = + fopen(xkm_fn, "r")) != NULL) { + xkmloadres = + XkmReadFile(tmpxkm, + XkmKeymapLegal, + XkmKeymapLegal, + &result); + xkl_debug(150, + "Loaded %s output as XKM file, got %d (comparing to %d)\n", + XKBCOMP, + (int) xkmloadres, + (int) + XkmKeymapLegal); + if ((int) xkmloadres != + (int) XkmKeymapLegal) { + xkl_debug(150, + "Loaded legal keymap\n"); + if (activate) { + xkl_debug + (150, + "Activating it...\n"); + if (XkbWriteToServer(&result)) { + xkl_debug + (150, + "Updating the keyboard...\n"); + xkb = result.xkb; + } else { + xkl_debug + (0, + "Could not write keyboard description to the server\n"); + } + } else /* no activate, just load */ + xkb = + result. + xkb; + } else { /* could not load properly */ + + xkl_debug(0, + "Could not load %s output as XKM file, got %d (asked %d)\n", + XKBCOMP, + (int) + xkmloadres, + (int) + XkmKeymapLegal); + } + fclose(tmpxkm); + xkl_debug(160, + "Unlinking the temporary xkm file %s\n", + xkm_fn); + if (xkl_debug_level < 500) { /* don't remove on high debug levels! */ + if (remove(xkm_fn) + == -1) + xkl_debug + (0, + "Could not unlink the temporary xkm file %s: %d\n", + xkm_fn, + errno); + } else + xkl_debug(500, + "Well, not really - the debug level is too high: %d\n", + xkl_debug_level); + } else { /* could not open the file */ + + xkl_debug(0, + "Could not open the temporary xkm file %s\n", + xkm_fn); + } + } else { /* could not assign to display */ + + xkl_debug(0, + "Could not change the keyboard description to display\n"); + } + if (xkb == NULL) + XkbFreeKeyboard(result.xkb, + XkbAllComponentsMask, + True); + break; + } + xkl_debug(160, + "Unlinking the temporary xkb file %s\n", + xkb_fn); + if (xkl_debug_level < 500) { /* don't remove on high debug levels! */ + if (remove(xkb_fn) == -1) + xkl_debug(0, + "Could not unlink the temporary xkb file %s: %d\n", + xkb_fn, errno); + } else + xkl_debug(500, + "Well, not really - the debug level is too high: %d\n", + xkl_debug_level); + } else { /* could not open input tmp file */ + + xkl_debug(0, + "Could not open tmp XKB file [%s]: %d\n", + xkb_fn, errno); + } + } else { + xkl_debug(0, "Could not get tmp names\n"); + } #endif - return xkb; + return xkb; } -#else /* no XKB headers */ -Bool _XklXkbConfigPrepareNative( const XklConfigRecPtr data, void * componentNamesPtr ) +#else /* no XKB headers */ +gboolean +xkl_xkb_config_native_prepare(const XklConfigRec * data, + gpointer componentNamesPtr) { - return False; + return FALSE; } -void _XklXkbConfigCleanupNative( void * componentNamesPtr ) +void +_XklXkbConfigCleanupNative(gpointer componentNamesPtr) { } #endif /* check only client side support */ -Bool _XklXkbConfigMultipleLayoutsSupported( void ) +gboolean +xkl_xkb_multiple_layouts_supported(XklEngine * engine) { - enum { NON_SUPPORTED, SUPPORTED, UNCHECKED }; + enum { NON_SUPPORTED, SUPPORTED, UNCHECKED }; - static int supportState = UNCHECKED; + static int support_state = UNCHECKED; - if( supportState == UNCHECKED ) - { - XklConfigRec data; - char *layouts[] = { "us", "de" }; - char *variants[] = { NULL, NULL }; + if (support_state == UNCHECKED) { + XklConfigRec data; + char *layouts[] = { "us", "de", NULL }; + char *variants[] = { NULL, NULL, NULL }; #ifdef XKB_HEADERS_PRESENT - XkbComponentNamesRec componentNames; - memset( &componentNames, 0, sizeof( componentNames ) ); + XkbComponentNamesRec component_names; + memset(&component_names, 0, sizeof(component_names)); #endif - data.model = "pc105"; - data.numVariants = - data.numLayouts = 2; - data.numOptions = 0; - data.layouts = layouts; - data.variants = variants; - data.options = NULL; + data.model = "pc105"; + data.layouts = layouts; + data.variants = variants; + data.options = NULL; - XklDebug( 100, "!!! Checking multiple layouts support\n" ); - supportState = NON_SUPPORTED; + xkl_debug(100, "!!! Checking multiple layouts support\n"); + support_state = NON_SUPPORTED; #ifdef XKB_HEADERS_PRESENT - if( _XklXkbConfigPrepareNative( &data, &componentNames ) ) - { - XklDebug( 100, "!!! Multiple layouts ARE supported\n" ); - supportState = SUPPORTED; - _XklXkbConfigCleanupNative( &componentNames ); - } else - { - XklDebug( 100, "!!! Multiple layouts ARE NOT supported\n" ); - } + if (xkl_xkb_config_native_prepare + (engine, &data, &component_names)) { + xkl_debug(100, + "!!! Multiple layouts ARE supported\n"); + support_state = SUPPORTED; + xkl_xkb_config_native_cleanup(engine, + &component_names); + } else { + xkl_debug(100, + "!!! Multiple layouts ARE NOT supported\n"); + } #endif - } - return supportState == SUPPORTED; + } + return support_state == SUPPORTED; } -Bool _XklXkbConfigActivate( const XklConfigRecPtr data ) +gboolean +xkl_xkb_activate_config_rec(XklEngine * engine, const XklConfigRec * data) { - Bool rv = False; + gboolean rv = FALSE; #if 0 - { - int i; - XklDebug( 150, "New model: [%s]\n", data->model ); - XklDebug( 150, "New layouts: %p\n", data->layouts ); - for( i = data->numLayouts; --i >= 0; ) - XklDebug( 150, "New layout[%d]: [%s]\n", i, data->layouts[i] ); - XklDebug( 150, "New variants: %p\n", data->variants ); - for( i = data->numVariants; --i >= 0; ) - XklDebug( 150, "New variant[%d]: [%s]\n", i, data->variants[i] ); - XklDebug( 150, "New options: %p\n", data->options ); - for( i = data->numOptions; --i >= 0; ) - XklDebug( 150, "New option[%d]: [%s]\n", i, data->options[i] ); - } + { + int i; + XklDebug(150, "New model: [%s]\n", data->model); + XklDebug(150, "New layouts: %p\n", data->layouts); + for (i = data->numLayouts; --i >= 0;) + XklDebug(150, "New layout[%d]: [%s]\n", i, + data->layouts[i]); + XklDebug(150, "New variants: %p\n", data->variants); + for (i = data->numVariants; --i >= 0;) + XklDebug(150, "New variant[%d]: [%s]\n", i, + data->variants[i]); + XklDebug(150, "New options: %p\n", data->options); + for (i = data->numOptions; --i >= 0;) + XklDebug(150, "New option[%d]: [%s]\n", i, + data->options[i]); + } #endif #ifdef XKB_HEADERS_PRESENT - XkbComponentNamesRec componentNames; - memset( &componentNames, 0, sizeof( componentNames ) ); - - if( _XklXkbConfigPrepareNative( data, &componentNames ) ) - { - XkbDescPtr xkb; - xkb = _XklConfigGetKeyboard( &componentNames, True ); - if( xkb != NULL ) - { - if( XklSetNamesProp - ( xklVTable->baseConfigAtom, _XklGetRulesSetName( XKB_DEFAULT_RULESET ), data ) ) - /* We do not need to check the result of _XklGetRulesSetName - - because PrepareBeforeKbd did it for us */ - rv = True; - else - _xklLastErrorMsg = "Could not set names property"; - XkbFreeKeyboard( xkb, XkbAllComponentsMask, True ); - } else - { - _xklLastErrorMsg = "Could not load keyboard description"; - } - _XklXkbConfigCleanupNative( &componentNames ); - } + XkbComponentNamesRec component_names; + memset(&component_names, 0, sizeof(component_names)); + + if (xkl_xkb_config_native_prepare(engine, data, &component_names)) { + XkbDescPtr xkb; + xkb = + xkl_config_get_keyboard(engine, &component_names, + TRUE); + if (xkb != NULL) { + if (xkl_config_rec_set_to_root_window_property + (data, + xkl_engine_priv(engine, base_config_atom), + xkl_engine_get_ruleset_name(engine, + XKB_DEFAULT_RULESET), + engine)) + /* We do not need to check the result of _XklGetRulesSetName - + because PrepareBeforeKbd did it for us */ + rv = TRUE; + else + xkl_last_error_message = + "Could not set names property"; + XkbFreeKeyboard(xkb, XkbAllComponentsMask, True); + } else { + xkl_last_error_message = + "Could not load keyboard description"; + } + xkl_xkb_config_native_cleanup(engine, &component_names); + } #endif - return rv; + return rv; } -Bool _XklXkbConfigWriteFile( const char *fileName, - const XklConfigRecPtr data, - const Bool binary ) +gboolean +xkl_xkb_write_config_rec_to_file(XklEngine * engine, const char *file_name, + const XklConfigRec * data, + const gboolean binary) { - Bool rv = False; + gboolean rv = FALSE; #ifdef XKB_HEADERS_PRESENT - XkbComponentNamesRec componentNames; - FILE *output = fopen( fileName, "w" ); - XkbFileInfo dumpInfo; - - if( output == NULL ) - { - _xklLastErrorMsg = "Could not open the XKB file"; - return False; - } - - memset( &componentNames, 0, sizeof( componentNames ) ); - - if( _XklXkbConfigPrepareNative( data, &componentNames ) ) - { - XkbDescPtr xkb; - xkb = _XklConfigGetKeyboard( &componentNames, False ); - if( xkb != NULL ) - { - dumpInfo.defined = 0; - dumpInfo.xkb = xkb; - dumpInfo.type = XkmKeymapFile; - if( binary ) - rv = XkbWriteXKMFile( output, &dumpInfo ); - else - rv = XkbWriteXKBFile( output, &dumpInfo, True, NULL, NULL ); - - XkbFreeKeyboard( xkb, XkbGBN_AllComponentsMask, True ); - } else - _xklLastErrorMsg = "Could not load keyboard description"; - _XklXkbConfigCleanupNative( &componentNames ); - } - fclose( output ); + XkbComponentNamesRec component_names; + FILE *output = fopen(file_name, "w"); + XkbFileInfo dump_info; + + if (output == NULL) { + xkl_last_error_message = "Could not open the XKB file"; + return FALSE; + } + + memset(&component_names, 0, sizeof(component_names)); + + if (xkl_xkb_config_native_prepare(engine, data, &component_names)) { + XkbDescPtr xkb; + xkb = + xkl_config_get_keyboard(engine, &component_names, + FALSE); + if (xkb != NULL) { + dump_info.defined = 0; + dump_info.xkb = xkb; + dump_info.type = XkmKeymapFile; + if (binary) + rv = XkbWriteXKMFile(output, &dump_info); + else + rv = XkbWriteXKBFile(output, &dump_info, + True, NULL, NULL); + + XkbFreeKeyboard(xkb, XkbGBN_AllComponentsMask, + True); + } else + xkl_last_error_message = + "Could not load keyboard description"; + xkl_xkb_config_native_cleanup(engine, &component_names); + } + fclose(output); #endif - return rv; + return rv; } |