From fbba1c150a3b726af9b932b84a9912ac9b802ddc Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Tue, 9 Jan 2001 19:40:57 +0000 Subject: - reintegrate into CVS - really fix X11 under X --- Makefile | 5 ++- enable_X11_numlock.1 | 8 +++- enable_X11_numlock.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++----- numlock.init | 14 +++--- numlock.sh | 4 +- numlock.spec | 49 +++++++++++++------- numlock.xinit | 2 +- 7 files changed, 168 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 2786cfa..d0ea5cb 100644 --- a/Makefile +++ b/Makefile @@ -16,13 +16,14 @@ clean: install: all install -d $(TOP)/usr/X11R6/{bin,man/man1}/ - install -d $(TOP)/etc/{profile.d,rc.d/init.d}/ + install -d $(TOP)/etc/profile.d + install -d $(TOP)/$(INITRDDIR) install -d $(TOP)/etc/X11/xinit.d install -m755 enable_X11_numlock $(TOP)/usr/X11R6/bin install -m755 enable_X11_numlock.1 $(TOP)/usr/X11R6/man/man1/ - install -m755 numlock.init $(TOP)/etc/rc.d/init.d/$(NAME) + install -m755 numlock.init $(TOP)/$(INITRDDIR)/$(NAME) install -m755 numlock.sh $(TOP)/etc/profile.d/ install -m755 numlock.xinit $(TOP)/etc/X11/xinit.d/numlock diff --git a/enable_X11_numlock.1 b/enable_X11_numlock.1 index 5db11d8..2849186 100644 --- a/enable_X11_numlock.1 +++ b/enable_X11_numlock.1 @@ -1,12 +1,16 @@ -.TH Enable_X11_Numlock "5 April 2000" "Linux Mandrake Manual" +.TH Enable_X11_Numlock "9 Jan 2001" "Linux Mandrake Manual" .SH NAME enable_X11_numlock \- Enable X11 numlock .SH SYNOPSIS .BI enable_X11_numlock +[on] +[off] +[switch] .SH DESCRIPTION The command .B enable_X11_numlock -makes active the numlock of X, that is no more no less :). +turns on, off, or switches the numlock under X. Default behaviour (e.g. +when no option is given) is to turn it on. .SH "SEE ALSO" diff --git a/enable_X11_numlock.c b/enable_X11_numlock.c index 836a4de..f35decf 100644 --- a/enable_X11_numlock.c +++ b/enable_X11_numlock.c @@ -1,13 +1,118 @@ +/**************************************************************************** + + NumlockX - (C) 2000 Lubos Lunak + Released under the terms of the GNU General Public License + + main.c - + + $Id$ + +****************************************************************************/ + +/* The NumLock state detection code is originally from KLeds by + Hans Matzen */ + +#define __main_C + +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include +#include +#include + +#define HAS_XKB 1 +#ifdef HAS_XKB +#include +#endif + +void usage( const char* argv0 ) + { + printf( "NumlockX - (C) 2000 Lubos Lunak \n\n" +#ifdef HAS_XKB + "Usage : %s [on|off|switch]\n" + "on - sets NumLock on in X (default)\n" + "off - sets NumLock off in X\n" + "switch - changes NumLock state in X\n" +#else + "Usage : %s\n" + "Changes NumLock state in X\n" + "( NumLock state detection not available," + " compiled without XKB )\n" +#endif + "\n" + , argv0 ); + } + +Display* disp; + +#ifdef HAS_XKB +int get_numlock_state() + { + unsigned int states; + if( XkbGetIndicatorState( disp, XkbUseCoreKbd, &states) != Success ) + { + printf("Error while reading Indicator status\n"); + XCloseDisplay( disp ); + exit( 3 ); + } + return states & 0x02; /* NumLock appears to be bit1 */ + } +#endif + +void change_numlock() + { + XTestFakeKeyEvent( disp, XKeysymToKeycode( disp, XK_Num_Lock ), True, CurrentTime ); + XTestFakeKeyEvent( disp, XKeysymToKeycode( disp, XK_Num_Lock ), False, CurrentTime ); + } + +#ifdef HAS_XKB +void set_on() + { + if( !get_numlock_state()) + change_numlock(); + } + +void set_off() + { + if( get_numlock_state()) + change_numlock(); + } +#endif -int main(int argc, char **argv) -{ - Display* disp = XOpenDisplay( NULL ); - if( disp == NULL ) - return 1; - XTestFakeKeyEvent( disp, XKeysymToKeycode( disp, XK_Num_Lock ), True, CurrentTime ); - XTestFakeKeyEvent( disp, XKeysymToKeycode( disp, XK_Num_Lock ), False, CurrentTime ); - XCloseDisplay( disp ); - return 0; -} +int main( int argc, char* argv[] ) + { + if( argc > 2 ) + { + usage( argv[ 0 ] ); + return 1; + } + disp = XOpenDisplay( NULL ); + if( disp == NULL ) + { + printf( "Error opening display\n" ); + return 2; + } + if( argc == 1 ) +#if HAS_XKB + set_on(); + else if( strncmp( argv[ 1 ], "on", 2 ) == 0 ) + set_on(); + else if( strncmp( argv[ 1 ], "of", 2 ) == 0 ) + set_off(); +#else + change_numlock(); /* if( argc == 1 ) */ +#endif + else if( strncmp( argv[ 1 ], "switch", 6 ) == 0 ) + change_numlock(); + else + { + usage( argv[ 0 ] ); + XCloseDisplay( disp ); + return 1; + } + XCloseDisplay( disp ); + return 0; + } diff --git a/numlock.init b/numlock.init index f196ff0..0f7e325 100755 --- a/numlock.init +++ b/numlock.init @@ -10,13 +10,13 @@ # The following file make bash to relock the numlock key when logging # since login unlock it. -#SYSCONF_FILE=/var/lock/subsys/NumLock -SYSCONF_FILE=/etc/sysconfig/NumLock +SYSCONF_FILE=/var/lock/subsys/numlock +#SYSCONF_FILE=/etc/sysconfig/numlock # See how we were called. case "$1" in start) - echo -n "Starting NumLock: " + echo -n "Starting numlock: " echo_success echo touch $SYSCONF_FILE @@ -27,7 +27,7 @@ case "$1" in ;; stop) - echo -n "Disabling NumLocks on ttys: " + echo -n "Disabling numlocks on ttys: " for tty in /dev/tty[1-8]; do setleds -D -num < $tty done @@ -40,9 +40,9 @@ case "$1" in # echo "dead status as reported is normal since NumLock doesn't need to daemonize" if [ -f $SYSCONF_FILE ] then - echo "NumLock is enabled" + echo "numlock is enabled" else - echo "NumLock is disabled" + echo "numlock is disabled" fi ;; restart) @@ -50,7 +50,7 @@ case "$1" in $0 start ;; reload) - echo -n "Reloading NumLock: " + echo -n "Reloading numlock: " $0 start echo ;; diff --git a/numlock.sh b/numlock.sh index b3a85fd..92a8962 100755 --- a/numlock.sh +++ b/numlock.sh @@ -1,9 +1,9 @@ # Linux-Mandrake configuration. -# ReLock the NumLock key if /etc/rc.d/init.d/NumLock has been runned +# ReLock the NumLock key if /etc/rc.d/init.d/numlock has been runned # This is needed as login reset the tty MY_TTY=`tty` case $MY_TTY in - /dev/tty[0-9]*) [ -f /etc/sysconfig/NumLock ] && setleds -D +num < $MY_TTY;; + /dev/tty[0-9]*) [ -f /etc/sysconfig/numlock ] && setleds -D +num < $MY_TTY;; esac unset MY_TTY \ No newline at end of file diff --git a/numlock.spec b/numlock.spec index 11b0d7c..8f9c2bc 100644 --- a/numlock.spec +++ b/numlock.spec @@ -1,38 +1,37 @@ -%define name numlock -%define version 1.0 -%define release 7mdk +# !!!!!!!! WARNING THIS HAS TO BE EDITED IN THE CVS !!!!!!!!!!! +# get the source from our cvs repository (see http://www.linuxmandrake.com/en/cvs.php3) +%define name numlock +%define version 2.0 +%define release 1mdk -Summary: Numlock key locker. +Summary: Numlock key locker Name: %{name} -Version: 1.0 +Version: %{version} Release: %{release} Copyright: GPL Group: System/Configuration/Boot and Init -# get the source from our cvs repository (see -# http://www.linuxmandrake.com/en/cvs.php3) Source0: %{name}-%{version}.tar.bz2 -Source1: numlock.xinit BuildRoot: %{_tmppath}/%{name}-buildroot -Requires: fileutils console-tools +autoReq: no +Requires: fileutils console-tools glibc Obsoletes: NumLock %description - NumLock enable to lock the numlock key. Only enable it at boot-time with ntsysv or with any other SVSR like rc.d config scripts editor such as tksysv or the ones from GNOME and KDE. NumLock is safe for portable as it is disabled by default. %prep -%setup +%setup -q %build make CFLAGS="$RPM_OPT_FLAGS" %install rm -rf $RPM_BUILD_ROOT -make install TOP=$RPM_BUILD_ROOT +make install TOP=$RPM_BUILD_ROOT INITRDDIR=%{_initrddir} %post /sbin/chkconfig --add numlock @@ -47,13 +46,33 @@ rm -rf $RPM_BUILD_ROOT %files %defattr(755,root,root) -%config /etc/rc.d/init.d/%{name} -%config /etc/profile.d/%{name}.sh -%config /etc/X11/xinit.d/numlock +%config(noreplace) %{_initrddir}/%{name} +%config(noreplace) /etc/profile.d/%{name}.sh +%config(noreplace) /etc/X11/xinit.d/numlock /usr/X11R6/bin/* /usr/X11R6/man/*/* %changelog +* Tue Jan 9 2001 Guillaume Cottenceau 2.0-1mdk +- really fix the xinit.d file +- reintegrate into CVS + +* Thu Nov 2 2000 Guillaume Cottenceau 1.0-11mdk +- fix the xinit.d file, thanks to fcrozat +- get latest code that ensure the numlock is on even if it was already + on, thx to fcrozat + +* Mon Sep 11 2000 Guillaume Cottenceau 1.0-10mdk +- tried to really fix numlock for fredl + +* Wed Aug 30 2000 Guillaume Cottenceau 1.0-9mdk +- added %{_initrddir} +- NumLock -> numlock by request of submarine ;-) +- %config(noreplace) + +* Wed Apr 26 2000 Pixel 1.0-8mdk +- force non-requiring XFree86-libs + * Wed Apr 12 2000 Frederic Lepied 1.0-7mdk - launch via /etc/X11/xinit.d diff --git a/numlock.xinit b/numlock.xinit index 66ddfcb..9d759c8 100755 --- a/numlock.xinit +++ b/numlock.xinit @@ -8,7 +8,7 @@ # Created On : Wed Apr 12 08:39:24 2000 #--------------------------------------------------------------- -if [ -f /etc/sysconfig/NumLock -a -x /usr/X11R6/bin/enable_X11_numlock ]; then +if [ -f /var/lock/subsys/numlock -a -x /usr/X11R6/bin/enable_X11_numlock ]; then /usr/X11R6/bin/enable_X11_numlock fi -- cgit v1.2.1