Subject: Add status command to numlockx
From: Michal Čihař <nijel@debian.org>
--- a/main.c
+++ b/main.c
@@ -54,10 +54,11 @@
     printf( "NumLockX " VERSION "\n"
         "(C) 2000-2001 Lubos Lunak <l.lunak@kde.org>\n"
         "(C) 2001      Oswald Buddenhagen <ossi@kde.org>\n\n"
-        "Usage: %s [on|off|toggle]\n"
+        "Usage: %s [on|off|toggle|status]\n"
         "on     - turns NumLock on in X ( default )\n"
         "off    - turns NumLock off in X\n"
         "toggle - toggles the NumLock on and off in X\n"
+        "status - gets the NumLock status\n"
         "\n"
         , argv0 );
     }
@@ -150,7 +151,25 @@
         XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, mask);
     return 1;
     }
-    
+
+int xkb_status()
+    {
+    unsigned int mask;
+    unsigned int numlockState;
+    XkbStateRec xkbState;
+    if( !xkb_init())
+        return 0;
+    mask = xkb_numlock_mask();
+    if( mask == 0 )
+        return 0;
+    XkbGetState( dpy, XkbUseCoreKbd, &xkbState);
+    numlockState = xkbState.locked_mods & mask;
+    if (numlockState)
+        printf("Numlock is on\n");
+    else
+        printf("Numlock is off\n");
+    return 1;
+    }
 #endif
 
 #ifdef HAVE_XTEST
@@ -200,6 +219,14 @@
     {
     xtest_change_numlock();
     }
+
+void xtest_status()
+    {
+    if( xtest_get_numlock_state())
+        printf("Numlock is on\n");
+    else
+        printf("Numlock is off\n");
+    }
 #endif
 
 void numlock_set_on()
@@ -235,6 +262,17 @@
 #endif
     }
 
+void numlock_status()
+    {
+#ifdef HAVE_XKB
+    if( xkb_status())
+        return;
+#endif
+#ifdef HAVE_XTEST
+    xtest_status();
+#endif
+    }
+
 int main( int argc, char* argv[] )
     {
     if( argc > 2 )
@@ -256,6 +294,8 @@
         numlock_set_off();
     else if( strcmp( argv[ 1 ], "toggle" ) == 0 )
         numlock_toggle();
+    else if( strcmp( argv[ 1 ], "status" ) == 0 )
+        numlock_status();
     else
         {
         usage( argv[ 0 ] );
