From d42a67c192d2c69561efec5cc1a33c4ce1db1ccd Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Wed, 5 Apr 2000 16:34:26 +0000 Subject: Initial revision --- Makefile | 20 +++++++++++++++++ enable_X11_numlock.c | 13 +++++++++++ numlock | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ numlock.sh | 10 +++++++++ 4 files changed, 105 insertions(+) create mode 100644 Makefile create mode 100644 enable_X11_numlock.c create mode 100755 numlock create mode 100755 numlock.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4e67373 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +TOP= +CFLAGS=-g -O2 -Wall +CC=gcc +FLAGS=-lX11 -lXtst -I/usr/X11R6/include -L/usr/X11R6/lib + +enable_X11_numlock: enable_X11_numlock.c + $(CC) $(CFLAGS) $(FLAGS) -o $@ $< + +all: enable_X11_numlock + +clean: + rm -f enable_X11_numlock core *.o + +install: all + install -d $(TOP)/usr/X11R6/bin/ + install -d $(TOP)/etc/{profile.d,rc.d/init.d}/ + + install -m755 enable_X11_numlock $(TOP)/usr/X11R6/bin + install -m755 numlock $(TOP)/etc/rc.d/init.d/ + install -m755 numlock.sh $(TOP)/etc/profile.d/ \ No newline at end of file diff --git a/enable_X11_numlock.c b/enable_X11_numlock.c new file mode 100644 index 0000000..836a4de --- /dev/null +++ b/enable_X11_numlock.c @@ -0,0 +1,13 @@ +#include +#include + +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; +} diff --git a/numlock b/numlock new file mode 100755 index 0000000..f196ff0 --- /dev/null +++ b/numlock @@ -0,0 +1,62 @@ +#!/bin/sh +# +# Startup script for NumLock +# +# description: Locks NumLock key at init runlevel change +# chkconfig: 345 85 15 + +# Source function library. +. /etc/rc.d/init.d/functions + +# 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 + +# See how we were called. +case "$1" in + start) + echo -n "Starting NumLock: " + echo_success + echo + touch $SYSCONF_FILE + + for tty in /dev/tty[1-8]; do + setleds -D +num < $tty + done + + ;; + stop) + echo -n "Disabling NumLocks on ttys: " + for tty in /dev/tty[1-8]; do + setleds -D -num < $tty + done + echo_success + echo + rm -f $SYSCONF_FILE + ;; + status) +# status NumLock +# echo "dead status as reported is normal since NumLock doesn't need to daemonize" + if [ -f $SYSCONF_FILE ] + then + echo "NumLock is enabled" + else + echo "NumLock is disabled" + fi + ;; + restart) + $0 stop + $0 start + ;; + reload) + echo -n "Reloading NumLock: " + $0 start + echo + ;; + *) + echo "Usage: $0 {start|stop|restart|reload|status}" + exit 1 +esac + +exit 0 diff --git a/numlock.sh b/numlock.sh new file mode 100755 index 0000000..39781d1 --- /dev/null +++ b/numlock.sh @@ -0,0 +1,10 @@ +# Linux-Mandrake configuration. +# 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/pts/[0-9]*) [ "XX$DISPLAY" != "XX" ] && [ -x /usr/X11R6/bin/enable_X11_numlock ] && /usr/X11R6/bin/enable_X11_numlock +esac +unset MY_TTY \ No newline at end of file -- cgit v1.2.1