summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Udaltsov <svu@gnome.org>2004-04-12 21:08:02 +0000
committerSergey Udaltsov <svu@gnome.org>2004-04-12 21:08:02 +0000
commitece30c7702cf5a510a91fb113c7cddf5452aa2be (patch)
tree4e45ba782c5084ff55a86d024b3b9323951ac8a3
parent1893463328ee634b863148894844e23ef13e4bcc (diff)
downloadlibxklavier-ece30c7702cf5a510a91fb113c7cddf5452aa2be.tar.gz
it seems we got runtime rules detection working
-rw-r--r--configure.in9
-rw-r--r--libxklavier/xklavier_config_xkb.c53
-rw-r--r--libxklavier/xklavier_props.c16
3 files changed, 56 insertions, 22 deletions
diff --git a/configure.in b/configure.in
index d313c53..f1259ec 100644
--- a/configure.in
+++ b/configure.in
@@ -2,7 +2,7 @@ AC_INIT(libxklavier/xklavier.c)
PACKAGE=libxklavier
MAJOR_VERSION=1
-MINOR_VERSION=01
+MINOR_VERSION=02
VERSION=$MAJOR_VERSION.$MINOR_VERSION
VERSION_INFO=8:0:0
@@ -64,13 +64,6 @@ fi
AC_DEFINE_UNQUOTED(XKB_BASE,"${xkb_base}",Base for XKB configuration)
-AC_ARG_WITH( xkb_rules_set,
- [ --with-xkb-rules-set=SET Set of XKB rules: xfree86, xorg, ... (by default it is xfree86)],
- xkb_rules_set="$withval",
- xkb_rules_set="xfree86" )
-
-AC_DEFINE_UNQUOTED(XKB_RULES_SET,"${xkb_rules_set}",Set of XKB rules)
-
ac_xkblib_include="\
#include <stdio.h>
#include <X11/Xlib.h>
diff --git a/libxklavier/xklavier_config_xkb.c b/libxklavier/xklavier_config_xkb.c
index 29e732d..1d0af43 100644
--- a/libxklavier/xklavier_config_xkb.c
+++ b/libxklavier/xklavier_config_xkb.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <locale.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include <libxml/xpath.h>
@@ -16,12 +17,6 @@
#include <X11/extensions/XKM.h>
#endif
-#define RULES_FILE XKB_RULES_SET
-
-#define RULES_PATH ( XKB_BASE "/rules/" RULES_FILE )
-
-#define XML_CFG_PATH ( XKB_BASE "/rules/" RULES_FILE ".xml" )
-
// For "bad" X servers we hold our own copy
#define XML_CFG_FALLBACK_PATH ( DATA_DIR "/xfree86.xml" )
@@ -39,20 +34,49 @@ static XkbComponentNamesRec componentNames;
static char *locale;
+static char* _XklGetRulesSet( void )
+{
+ static char* rf = NULL;
+ if ( rf == NULL )
+ if( !XklGetNamesProp( _xklAtoms[XKB_RF_NAMES_PROP_ATOM], &rf, NULL ) )
+ return NULL;
+ XklDebug( 100, "Rules set: [%s]\n", rf );
+ return rf;
+//!! tiny memory leak which hopefully can be afforded
+}
+
Bool XklConfigLoadRegistry( void )
{
struct stat statBuf;
-
- const char *fileName = XML_CFG_PATH;
- if( stat( XML_CFG_PATH, &statBuf ) != 0 )
- fileName = XML_CFG_FALLBACK_PATH;
-
+ char fileName[MAXPATHLEN] = "";
+ char* rf = _XklGetRulesSet();
+
+ if ( rf == NULL )
+ return False;
+
+ snprintf( fileName, sizeof fileName, XKB_BASE "/rules/%s.xml", rf );
+
+ if( stat( fileName, &statBuf ) != 0 )
+ {
+ strncpy( fileName, XML_CFG_FALLBACK_PATH, sizeof fileName );
+ fileName[ MAXPATHLEN - 1 ] = '\0';
+ }
+
return XklConfigLoadRegistryFromFile( fileName );
}
static Bool _XklConfigPrepareBeforeKbd( const XklConfigRecPtr data )
{
#ifdef XKB_HEADERS_PRESENT
+ char fileName[MAXPATHLEN] = "";
+ char* rf = _XklGetRulesSet();
+
+ if( rf == NULL )
+ {
+ _xklLastErrorMsg = "Could not find the XKB rules set";
+ return False;
+ }
+
memset( &_xklVarDefs, 0, sizeof( _xklVarDefs ) );
_xklVarDefs.model = ( char * ) data->model;
@@ -70,7 +94,8 @@ static Bool _XklConfigPrepareBeforeKbd( const XklConfigRecPtr data )
if( locale != NULL )
locale = strdup( locale );
- rules = XkbRF_Load( RULES_PATH, locale, True, True );
+ snprintf( fileName, sizeof fileName, XKB_BASE "/rules/%s", rf );
+ rules = XkbRF_Load( fileName, locale, True, True );
if( rules == NULL )
{
@@ -150,7 +175,9 @@ Bool XklConfigActivate( const XklConfigRecPtr data,
if( xkb != NULL )
{
if( XklSetNamesProp
- ( _xklAtoms[XKB_RF_NAMES_PROP_ATOM], RULES_FILE, data ) )
+ ( _xklAtoms[XKB_RF_NAMES_PROP_ATOM], _XklGetRulesSet(), data ) )
+ // We do not need to check the result of _XklGetRulesSet -
+ // because PrepareBeforeKbd did it for us
rv = True;
else
_xklLastErrorMsg = "Could not set names property";
diff --git a/libxklavier/xklavier_props.c b/libxklavier/xklavier_props.c
index 4ab8cf9..83518f4 100644
--- a/libxklavier/xklavier_props.c
+++ b/libxklavier/xklavier_props.c
@@ -215,7 +215,7 @@ Bool XklGetNamesProp( Atom rulesAtom,
Atom realPropType;
int fmt;
unsigned long nitems, extraBytes;
- char *propData, *out;
+ char *propData = NULL, *out;
Status rtrn;
// no such atom!
@@ -248,12 +248,26 @@ Bool XklGetNamesProp( Atom rulesAtom,
_xklLastErrorMsg = "Wrong property format";
return False;
}
+
+ if( !propData )
+ {
+ _xklLastErrorMsg = "No properties returned";
+ return False;
+ }
+
// rules file
out = propData;
if( out && ( *out ) && rulesFileOut )
*rulesFileOut = strdup( out );
out += strlen( out ) + 1;
+ // if user is interested in rules only - don't waste the time
+ if( !data )
+ {
+ XFree( propData );
+ return True;
+ }
+
if( ( out - propData ) < nitems )
{
if( *out )