From d431ef4a3ca6228954ddb21e2e4a88f0cf9e8624 Mon Sep 17 00:00:00 2001 From: Sergey Udaltsov Date: Thu, 25 Nov 2004 23:17:30 +0000 Subject: first commit with xmodmap support --- tests/test_config.c | 49 ++++++++++++++++++----------------------------- tests/test_monitor.c | 54 ++++++++++++++++++++++++---------------------------- 2 files changed, 44 insertions(+), 59 deletions(-) (limited to 'tests') diff --git a/tests/test_config.c b/tests/test_config.c index ad2c4f0..cf01482 100644 --- a/tests/test_config.c +++ b/tests/test_config.c @@ -1,12 +1,22 @@ #include #include #include +#include #include #include #include #include #include +#ifdef __STRICT_ANSI__ +/* these are functions which are NOT in ANSI C. + Probably we should provide the implementation */ +extern char *strdup( const char *s ); +#endif + +extern void XklConfigDump( FILE* file, + XklConfigRecPtr data ); + enum { ACTION_NONE, ACTION_GET, ACTION_SET, ACTION_WRITE }; static void printUsage() @@ -21,28 +31,6 @@ static void printUsage() printf( " -h - Show this help\n" ); } -static void dump( XklConfigRecPtr ptr ) -{ - int i,j; - char**p; - XklDebug( 0, " model: [%s]\n", ptr->model ); - - XklDebug( 0, " layouts(%d):\n", ptr->numLayouts ); - p = ptr->layouts; - for( i = ptr->numLayouts, j = 0; --i >= 0; ) - XklDebug( 0, " %d: [%s]\n", j++, *p++ ); - - XklDebug( 0, " variants(%d):\n", ptr->numVariants ); - p = ptr->variants; - for( i = ptr->numVariants, j = 0; --i >= 0; ) - XklDebug( 0, " %d: [%s]\n", j++, *p++ ); - - XklDebug( 0, " options(%d):\n", ptr->numOptions ); - p = ptr->options; - for( i = ptr->numOptions, j = 0; --i >= 0; ) - XklDebug( 0, " %d: [%s]\n", j++, *p++ ); -} - int main( int argc, char * const argv[] ) { int c, i; @@ -50,7 +38,7 @@ int main( int argc, char * const argv[] ) const char* model = NULL; const char* layouts = NULL; const char* options = NULL; - int debugLevel = 0; + int debugLevel = -1; int binary = 0; Display *dpy; @@ -109,13 +97,14 @@ int main( int argc, char * const argv[] ) if ( !XklInit( dpy ) ) { XklConfigRec currentConfig, r2; - XklSetDebugLevel( debugLevel ); + if( debugLevel != -1 ) + XklSetDebugLevel( debugLevel ); XklDebug( 0, "Xklavier initialized\n" ); XklConfigInit(); XklConfigLoadRegistry(); XklDebug( 0, "Xklavier registry loaded\n" ); - XklDebug( 0, "Multiple layouts are %ssupported\n", - XklMultipleLayoutsSupported() ? "" : "not " ); + XklDebug( 0, "Bakend: [%s]\n", XklGetBackendName() ); + XklDebug( 0, "Supported features: 0x0%X\n", XklGetBackendFeatures() ); XklConfigRecInit( ¤tConfig ); XklConfigGetFromServer( ¤tConfig ); @@ -124,14 +113,14 @@ int main( int argc, char * const argv[] ) { case ACTION_GET: XklDebug( 0, "Got config from the server\n" ); - dump( ¤tConfig ); + XklConfigDump( stdout, ¤tConfig ); XklConfigRecInit( &r2 ); if ( XklConfigGetFromBackup( &r2 ) ) { XklDebug( 0, "Got config from the backup\n" ); - dump( &r2 ); + XklConfigDump( stdout, &r2 ); } if ( XklConfigActivate( &r2 ) ) @@ -191,7 +180,7 @@ int main( int argc, char * const argv[] ) } XklDebug( 0, "New config:\n" ); - dump( ¤tConfig ); + XklConfigDump( stdout, ¤tConfig ); if ( XklConfigActivate( ¤tConfig ) ) XklDebug( 0, "Set the config\n" ); else @@ -215,7 +204,7 @@ int main( int argc, char * const argv[] ) XklTerm(); } else { - fprintf( stderr, "Could not init Xklavier\n" ); + fprintf( stderr, "Could not init Xklavier: %s\n", XklGetLastError() ); exit(2); } printf( "closing display: %p\n", dpy ); diff --git a/tests/test_monitor.c b/tests/test_monitor.c index 8808b62..515c328 100644 --- a/tests/test_monitor.c +++ b/tests/test_monitor.c @@ -1,52 +1,41 @@ #include #include #include +#include #include #include #include #include #include +extern void XklConfigDump( FILE* file, + XklConfigRecPtr data ); + static void printUsage() { - printf( "Usage: test_monitor (-h)|(-d )\n" ); + printf( "Usage: test_monitor (-l1)(-l2)(-l3)(-h)(-d )\n" ); printf( "Options:\n" ); printf( " -d - Set the debug level (by default, 0)\n" ); printf( " -h - Show this help\n" ); -} - -void dump( XklConfigRecPtr ptr ) -{ - int i,j; - char**p; - XklDebug( 0, " model: [%s]\n", ptr->model ); - - XklDebug( 0, " layouts(%d):\n", ptr->numLayouts ); - p = ptr->layouts; - for( i = ptr->numLayouts, j = 0; --i >= 0; ) - XklDebug( 0, " %d: [%s]\n", j++, *p++ ); - - XklDebug( 0, " variants(%d):\n", ptr->numVariants ); - p = ptr->variants; - for( i = ptr->numVariants, j = 0; --i >= 0; ) - XklDebug( 0, " %d: [%s]\n", j++, *p++ ); - - XklDebug( 0, " options(%d):\n", ptr->numOptions ); - p = ptr->options; - for( i = ptr->numOptions, j = 0; --i >= 0; ) - XklDebug( 0, " %d: [%s]\n", j++, *p++ ); + printf( " -l1 - listen to manage layouts\n" ); + printf( " -l2 - listen to manage window states\n" ); + printf( " -l3 - listen to track the keyboard state\n" ); } int main( int argc, char * argv[] ) { int c; - int debugLevel = 0; + int debugLevel = -1; XkbEvent ev; Display* dpy; + int listenerType = 0, lt; + int listenerTypes[] = { XKLL_MANAGE_LAYOUTS, + XKLL_MANAGE_WINDOW_STATES, + XKLL_TRACK_KEYBOARD_STATE }; while (1) { - c = getopt( argc, argv, "hd:" ); + c = getopt( argc, argv, "hd:l:" ); if ( c == -1 ) break; switch (c) @@ -57,6 +46,11 @@ int main( int argc, char * argv[] ) case 'd': debugLevel = atoi( optarg ); break; + case 'l': + lt = optarg[0] - '1'; + if( lt >= 0 && lt < sizeof(listenerTypes)/sizeof(listenerTypes[0]) ) + listenerType |= listenerTypes[lt]; + break; default: fprintf( stderr, "?? getopt returned character code 0%o ??\n", c ); printUsage(); @@ -71,10 +65,11 @@ int main( int argc, char * argv[] ) exit(1); } printf( "opened display: %p\n", dpy ); - if ( !XklInit( dpy ) ) + if( !XklInit( dpy ) ) { XklConfigRec currentConfig; - XklSetDebugLevel( debugLevel ); + if( debugLevel != -1 ) + XklSetDebugLevel( debugLevel ); XklDebug( 0, "Xklavier initialized\n" ); XklConfigInit(); XklConfigLoadRegistry(); @@ -83,7 +78,8 @@ int main( int argc, char * argv[] ) XklConfigRecInit( ¤tConfig ); XklConfigGetFromServer( ¤tConfig ); - XklStartListen(); + XklDebug( 0, "Now, listening...\n" ); + XklStartListen( listenerType ); while (1) { @@ -103,7 +99,7 @@ int main( int argc, char * argv[] ) XklTerm(); } else { - fprintf( stderr, "Could not init Xklavier\n" ); + fprintf( stderr, "Could not init Xklavier: %s\n", XklGetLastError() ); exit(2); } printf( "closing display: %p\n", dpy ); -- cgit v1.2.1