summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Udaltsov <svu@gnome.org>2004-09-26 02:57:09 +0000
committerSergey Udaltsov <svu@gnome.org>2004-09-26 02:57:09 +0000
commit6721b0bb8b1b939ffe5de63737e24aa94ea3211b (patch)
treec53c956b2d2a05ac50af1778377d9b2490dd75cd /tests
parent8886e3181e95610128a5887d1a05664e6037edc9 (diff)
downloadlibxklavier-6721b0bb8b1b939ffe5de63737e24aa94ea3211b.tar.gz
monitor is working somehow, more when needed
Diffstat (limited to 'tests')
-rw-r--r--tests/test_config.c4
-rw-r--r--tests/test_monitor.c141
2 files changed, 28 insertions, 117 deletions
diff --git a/tests/test_config.c b/tests/test_config.c
index 53053cc..c70761c 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -8,7 +8,7 @@ enum { ACTION_NONE, ACTION_GET, ACTION_SET };
static void printUsage()
{
- printf( "Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)\n" );
+ printf( "Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)|(-h)\n" );
printf( "Options:\n" );
printf( " -g - Dump the current config, load original system settings and revert back\n" );
printf( " -s - Set the configuration given my -m -l -o options. Similar to setxkbmap\n" );
@@ -50,7 +50,7 @@ int main( int argc, char * const argv[] )
c = getopt( argc, argv, "hsgm:l:o:" );
if ( c == -1 )
break;
- switch(c)
+ switch (c)
{
case 's':
printf( "Set the config\n" );
diff --git a/tests/test_monitor.c b/tests/test_monitor.c
index 53053cc..472e07c 100644
--- a/tests/test_monitor.c
+++ b/tests/test_monitor.c
@@ -1,17 +1,17 @@
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/XKBlib.h>
#include <libxklavier/xklavier.h>
#include <libxklavier/xklavier_config.h>
-enum { ACTION_NONE, ACTION_GET, ACTION_SET };
-
static void printUsage()
{
- printf( "Usage: test_config (-g)|(-s -m <model> -l <layouts> -o <options>)\n" );
+ printf( "Usage: test_monitor (-h)|(-d <debugLevel>)\n" );
printf( "Options:\n" );
- printf( " -g - Dump the current config, load original system settings and revert back\n" );
- printf( " -s - Set the configuration given my -m -l -o options. Similar to setxkbmap\n" );
+ printf( " -d - Set the debug level (by default, 0)\n" );
printf( " -h - Show this help\n" );
}
@@ -37,53 +37,32 @@ static void dump( XklConfigRecPtr ptr )
XklDebug( 0, " %d: [%s]\n", j++, *p++ );
}
-int main( int argc, char * const argv[] )
+int main( int argc, char * argv[] )
{
- int c, i;
- int action = ACTION_NONE;
- const char* model = NULL;
- const char* layouts = NULL;
- const char* options = NULL;
+ int c;
+ int debugLevel = 0;
+ XkbEvent ev;
while (1)
{
- c = getopt( argc, argv, "hsgm:l:o:" );
+ c = getopt( argc, argv, "hd:" );
if ( c == -1 )
break;
- switch(c)
+ switch (c)
{
- case 's':
- printf( "Set the config\n" );
- action = ACTION_SET;
- break;
- case 'g':
- printf( "Get the config\n" );
- action = ACTION_GET;
- break;
- case 'm':
- printf( "Model: [%s]\n", model = optarg );
- break;
- case 'l':
- printf( "Layouts: [%s]\n", layouts = optarg );
- break;
- case 'o':
- printf( "Options: [%s]\n", options = optarg );
- break;
case 'h':
printUsage();
exit(0);
+ case 'd':
+ debugLevel = atoi( optarg );
+ break;
default:
fprintf( stderr, "?? getopt returned character code 0%o ??\n", c );
printUsage();
+ exit(0);
}
}
- if ( action == ACTION_NONE )
- {
- printUsage();
- exit( 0 );
- }
-
Display* dpy = XOpenDisplay( NULL );
if ( dpy == NULL )
{
@@ -93,96 +72,28 @@ int main( int argc, char * const argv[] )
printf( "opened display: %p\n", dpy );
if ( !XklInit( dpy ) )
{
- XklConfigRec currentConfig, r2;
+ XklConfigRec currentConfig;
+ XklSetDebugLevel( debugLevel );
XklDebug( 0, "Xklavier initialized\n" );
XklConfigInit();
XklConfigLoadRegistry();
XklDebug( 0, "Xklavier registry loaded\n" );
- XklDebug( 0, "Multiple layouts are %ssupported\n",
- XklMultipleLayoutsSupported() ? "" : "not " );
XklConfigRecInit( &currentConfig );
XklConfigGetFromServer( &currentConfig );
- switch ( action )
- {
- case ACTION_GET:
- XklDebug( 0, "Got config from the server\n" );
- dump( &currentConfig );
-
- XklConfigRecInit( &r2 );
-
- if ( XklConfigGetFromBackup( &r2 ) )
- {
- XklDebug( 0, "Got config from the backup\n" );
- dump( &r2 );
- }
-
- if ( XklConfigActivate( &r2, NULL ) )
- {
- XklDebug( 0, "The backup configuration restored\n" );
- if ( XklConfigActivate( &currentConfig, NULL ) )
- {
- XklDebug( 0, "Reverting the configuration change\n" );
- } else
- {
- XklDebug( 0, "The configuration could not be reverted: %s\n", XklGetLastError() );
- }
- } else
- {
- XklDebug( 0, "The backup configuration could not be restored: %s\n", XklGetLastError() );
- }
-
- XklConfigRecDestroy( &r2 );
- break;
- case ACTION_SET:
- if ( model != NULL )
- {
- if ( currentConfig.model != NULL ) free ( currentConfig.model );
- currentConfig.model = strdup( model );
- }
+ XklStartListen();
- if ( layouts != NULL )
- {
- if ( currentConfig.layouts != NULL )
- {
- for ( i = currentConfig.numLayouts; --i >=0; )
- free ( currentConfig.layouts[i] );
- free ( currentConfig.layouts );
- for ( i = currentConfig.numVariants; --i >=0; )
- free ( currentConfig.variants[i] );
- free ( currentConfig.variants );
- }
- currentConfig.numLayouts =
- currentConfig.numVariants = 1;
- currentConfig.layouts = malloc( sizeof ( char* ) );
- currentConfig.layouts[0] = strdup( layouts );
- currentConfig.variants = malloc( sizeof ( char* ) );
- currentConfig.variants[0] = strdup( "" );
- }
-
- if ( options != NULL )
- {
- if ( currentConfig.options != NULL )
- {
- for ( i = currentConfig.numOptions; --i >=0; )
- free ( currentConfig.options[i] );
- free ( currentConfig.options );
- }
- currentConfig.numOptions = 1;
- currentConfig.options = malloc( sizeof ( char* ) );
- currentConfig.options[0] = strdup( options );
- }
-
- XklDebug( 0, "New config:\n" );
- dump( &currentConfig );
- if ( XklConfigActivate( &currentConfig, NULL ) )
- XklDebug( 0, "Set the config\n" );
- else
- XklDebug( 0, "Could not set the config: %s\n", XklGetLastError() );
- break;
+ while (1)
+ {
+ int grp;
+ XNextEvent( dpy, &ev.core );
+ if ( XklFilterEvents( &ev.core ) )
+ XklDebug( 200, "Unknown event %d\n", ev.type );
}
+ XklStopListen();
+
XklConfigRecDestroy( &currentConfig );
XklConfigFreeRegistry();