Browse Source

added numlock option and functions, support for numpad Enter

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/slim/trunk@92 7c53e7cc-98ea-0310-8f1f-a0b24da60408
sip 16 years ago
parent
commit
66fcd45e63
11 changed files with 160 additions and 10 deletions
  1. 2 1
      ChangeLog
  2. 2 2
      Makefile
  3. 2 2
      Makefile.freebsd
  4. 2 2
      Makefile.netbsd
  5. 4 1
      Makefile.openbsd
  6. 9 1
      app.cpp
  7. 1 0
      cfg.cpp
  8. 1 1
      input.cpp
  9. 103 0
      numlock.cpp
  10. 31 0
      numlock.h
  11. 3 0
      slim.conf

+ 2 - 1
ChangeLog

@@ -1,7 +1,8 @@
 1.2.4 - work in progress
     * Added commands for session start and stop
       (i.e. for session registering)
-
+	* Added automatic numlock on/off option
+	* Support for numpad Enter key
 
 1.2.3 - 2005.09.11
     * Added FreeBSD, NetBSD, OpenBSD support

+ 2 - 2
Makefile

@@ -16,12 +16,12 @@ DESTDIR=
 #######################################################
 
 NAME=slim
-VERSION=1.2.3
+VERSION=1.2.4
 
 DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
-OBJECTS=jpeg.o png.o main.o image.o cfg.o switchuser.o input.o app.o panel.o
+OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
 
 all: slim
 

+ 2 - 2
Makefile.freebsd

@@ -16,12 +16,12 @@ DESTDIR=
 #######################################################
 
 NAME=slim
-VERSION=1.2.3
+VERSION=1.2.4
 
 DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
-OBJECTS=jpeg.o png.o main.o image.o cfg.o switchuser.o input.o app.o panel.o
+OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
 
 all: slim
 

+ 2 - 2
Makefile.netbsd

@@ -16,12 +16,12 @@ DESTDIR=
 #######################################################
 
 NAME=slim
-VERSION=1.2.3
+VERSION=1.2.4
 
 DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
 
-OBJECTS=jpeg.o png.o main.o image.o cfg.o switchuser.o input.o app.o panel.o
+OBJECTS=jpeg.o png.o main.o image.o numlock.o cfg.o switchuser.o input.o app.o panel.o
 
 all: slim
 

+ 4 - 1
Makefile.openbsd

@@ -16,7 +16,7 @@ DESTDIR=
 #######################################################
 
 NAME=slim
-VERSION=1.2.3
+VERSION=1.2.4
 
 DEFINES=-DPACKAGE=\"$(NAME)\" -DVERSION=\"$(VERSION)\" \
 		-DPKGDATADIR=\"$(PREFIX)/share/slim\" -DSYSCONFDIR=\"$(CFGDIR)\"
@@ -36,6 +36,9 @@ main.o:
 image.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c image.cpp -o $@
 
+numlock.o:
+	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c numlock.cpp -o $@
+
 cfg.o:
 	$(CXX) $(CFLAGS) $(DEFINES) $(CUSTOM) -c cfg.cpp -o $@
 

+ 9 - 1
app.cpp

@@ -21,6 +21,7 @@
 #include <vector>
 #include <algorithm>
 #include "app.h"
+#include "numlock.h"
 #include "image.h"
 
 
@@ -593,7 +594,14 @@ int App::StartServer() {
         break;
     }
 
-    delete args;
+    string numlock = cfg.getOption("numlock");
+    if (numlock == "on") {
+        NumLock::setOn();
+    } else if (numlock == "off") {
+        NumLock::setOff();
+	}
+    
+	delete args;
 
     return ServerPID;
 }

+ 1 - 0
cfg.cpp

@@ -24,6 +24,7 @@ Cfg::Cfg() {
     options.insert(option("default_path","./:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin"));
     options.insert(option("default_xserver","/usr/X11R6/bin/X"));
     options.insert(option("xserver_arguments",""));
+    options.insert(option("numlock",""));
     options.insert(option("login_cmd","exec /bin/bash -login ~/.xinitrc %session"));
     options.insert(option("halt_cmd","/sbin/shutdown -h now"));
     options.insert(option("reboot_cmd","/sbin/shutdown -r now"));

+ 1 - 1
input.cpp

@@ -42,7 +42,7 @@ char Input::Key(char ascii, KeySym keysym, bool singleInputMode) {
         } else {
             Field = GET_NAME;
         }
-    } else if(keysym == XK_Return) {
+    } else if(keysym == XK_Return || keysym == XK_KP_Enter) {
         if(!strcmp(NameBuffer, ""))
             return tmp;
 

+ 103 - 0
numlock.cpp

@@ -0,0 +1,103 @@
+/* SLiM - Simple Login Manager
+   Copyright (C) 2004-05 Simone Rota <sip@varlock.com>
+   Copyright (C) 2004-05 Johannes Winkelmann <jw@tks6.net>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   Code adapted from NumLockX, look at the end of this file for
+   the original Copyright information.
+
+*/
+
+#include "numlock.h"
+#include <string.h>
+
+NumLock::NumLock() {
+}
+
+int NumLock::xkb_init(Display* dpy) {
+    int xkb_opcode, xkb_event, xkb_error;
+    int xkb_lmaj = XkbMajorVersion;
+    int xkb_lmin = XkbMinorVersion;
+    return XkbLibraryVersion( &xkb_lmaj, &xkb_lmin )
+        && XkbQueryExtension( dpy, &xkb_opcode, &xkb_event, &xkb_error,
+			       &xkb_lmaj, &xkb_lmin );
+}
+    
+unsigned int NumLock::xkb_mask_modifier( XkbDescPtr xkb, const char *name ) {
+    int i;
+    if( !xkb || !xkb->names )
+	return 0;
+    for( i = 0; i < XkbNumVirtualMods; i++ ) {
+	    char* modStr = XGetAtomName( xkb->dpy, xkb->names->vmods[i] );
+	    if( modStr != NULL && strcmp(name, modStr) == 0 ) {
+	        unsigned int mask;
+	        XkbVirtualModsToReal( xkb, 1 << i, &mask );
+	        return mask;
+        }
+    }
+    return 0;
+}
+
+unsigned int NumLock::xkb_numlock_mask(Display* dpy) {
+    XkbDescPtr xkb;
+    if(( xkb = XkbGetKeyboard( dpy, XkbAllComponentsMask, XkbUseCoreKbd )) != NULL ) {
+        unsigned int mask = xkb_mask_modifier( xkb, "NumLock" );
+        XkbFreeKeyboard( xkb, 0, True );
+        return mask;
+    }
+    return 0;
+}
+        
+void NumLock::setOn() {
+    unsigned int mask;
+    Display* dpy = XOpenDisplay( NULL );
+    if( !xkb_init(dpy))
+        return;
+    mask = xkb_numlock_mask(dpy);
+    if( mask == 0 )
+        return;
+    XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, mask);
+    XCloseDisplay( dpy );
+}
+    
+void NumLock::setOff() {
+    unsigned int mask;
+    Display* dpy = XOpenDisplay( NULL );
+    if( !xkb_init(dpy))
+        return;
+    mask = xkb_numlock_mask(dpy);
+    if( mask == 0 )
+        return;
+    XkbLockModifiers ( dpy, XkbUseCoreKbd, mask, 0);
+    XCloseDisplay( dpy );
+}
+ 
+ 
+
+/* 
+ Copyright (C) 2000-2001 Lubos Lunak        <l.lunak@kde.org>
+ Copyright (C) 2001      Oswald Buddenhagen <ossi@kde.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+*/

+ 31 - 0
numlock.h

@@ -0,0 +1,31 @@
+/* SLiM - Simple Login Manager
+   Copyright (C) 2004-05 Simone Rota <sip@varlock.com>
+   Copyright (C) 2004-05 Johannes Winkelmann <jw@tks6.net>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+*/
+
+#ifndef _NUMLOCK_H_
+#define _NUMLOCK_H_
+
+#include <X11/Xlib.h>
+#include <X11/XKBlib.h>
+#include <X11/keysym.h>
+
+class NumLock {
+
+public:
+    NumLock();
+    static void setOn();
+    static void setOff();
+
+private:
+    static int xkb_init(Display* dpy);
+    static unsigned int xkb_mask_modifier( XkbDescPtr xkb, const char *name );
+    static unsigned int xkb_numlock_mask(Display* dpy);
+};
+
+#endif

+ 3 - 0
slim.conf

@@ -9,6 +9,9 @@ reboot_cmd          /sbin/shutdown -r now
 console_cmd         /usr/X11R6/bin/xterm -C -fg white -bg black +sb -T "Console login" -e /bin/sh -c "/bin/cat /etc/issue; exec /bin/login"
 #suspend_cmd        /usr/sbin/suspend
 
+# Activate numlock when slim starts. Valid values: on|off
+numlock             on
+
 # This command is executed after a succesful login.
 # you can place the %session and %theme variables
 # to handle launching of specific commands in .xinitrc