1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
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 ] );
|