From 6721b0bb8b1b939ffe5de63737e24aa94ea3211b Mon Sep 17 00:00:00 2001 From: Sergey Udaltsov Date: Sun, 26 Sep 2004 02:57:09 +0000 Subject: monitor is working somehow, more when needed --- tests/test_config.c | 4 +- tests/test_monitor.c | 141 ++++++++++----------------------------------------- 2 files changed, 28 insertions(+), 117 deletions(-) (limited to 'tests') 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 -l -o )\n" ); + printf( "Usage: test_config (-g)|(-s -m -l -o )|(-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 +#include #include #include +#include +#include #include #include -enum { ACTION_NONE, ACTION_GET, ACTION_SET }; - static void printUsage() { - printf( "Usage: test_config (-g)|(-s -m -l -o )\n" ); + printf( "Usage: test_monitor (-h)|(-d )\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( ¤tConfig ); XklConfigGetFromServer( ¤tConfig ); - switch ( action ) - { - case ACTION_GET: - XklDebug( 0, "Got config from the server\n" ); - dump( ¤tConfig ); - - 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( ¤tConfig, 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( ¤tConfig ); - if ( XklConfigActivate( ¤tConfig, 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( ¤tConfig ); XklConfigFreeRegistry(); -- cgit v1.2.1