[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/kcontrol/keyboard
From:       Andriy Rysin <arysin () gmail ! com>
Date:       2010-09-11 16:33:52
Message-ID: 20100911163352.11DC3AC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1174244 by rysin:

use numlockx code to reliably set numlock

 M  +5 -0      CMakeLists.txt  
 M  +3 -59     keyboard_hardware.cpp  
 A             numlockx.c   [License: BSD X11 (BSD like)]


--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/CMakeLists.txt #1174243:1174244
@@ -19,6 +19,7 @@
     xkb_helper.cpp
     keyboard_config.cpp
     keyboard_hardware.cpp
+    numlockx.c
     bindings.cpp
     utils.cpp
 # next are temporary for sys tray UI
@@ -35,6 +36,10 @@
  	${QT_QTXML_LIBRARY} ${X11_Xkbfile_LIB}
  )
 
+if(X11_XTest_FOUND)
+  target_link_libraries(kded_keyboard ${X11_XTest_LIB})
+endif(X11_XTest_FOUND)
+
 if(XiGetDevicePresence_FOUND)
   target_link_libraries(kded_keyboard ${X11_Xinput_LIB})
 endif(XiGetDevicePresence_FOUND)
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/keyboard_hardware.cpp #1174243:1174244
@@ -29,6 +29,8 @@
 
 #include "x11_helper.h"
 
+// from numlockx.c
+extern "C" void numlockx_change_numlock_state(Display* dpy, int state);
 
 /*
  Originally comes from NumLockX http://dforce.sh.cvut.cz/~seli/en/numlockx
@@ -62,64 +64,6 @@
 #include <X11/keysym.h>
 
 
-static
-unsigned int xkb_mask_modifier( XkbDescPtr xkb, const char *name )
-{
-	if( !xkb || !xkb->names )
-		return 0;
-
-	for(int 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;
-}
-
-static
-unsigned int xkb_numlock_mask()
-{
-	XkbDescPtr xkb;
-	if(( xkb = XkbGetKeyboard( QX11Info::display(), XkbAllComponentsMask, XkbUseCoreKbd )) != NULL ) {
-		unsigned int mask = xkb_mask_modifier( xkb, "NumLock" );
-		XkbFreeKeyboard( xkb, 0, True );
-		return mask;
-	}
-	else {
-		kError() << "Failed to set numlock: failed to get keyboard";
-	}
-	return 0;
-}
-
-static
-int xkb_set_numlock(int set)
-{
-    unsigned int mask = xkb_numlock_mask();
-    if( mask == 0 ) {
-    	kError() << "Failed to set numlock: numlock mask is 0";
-        return 0;
-    }
-
-    unsigned int values = set ? mask : 0;
-    return XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd, mask, values);
-}
-
-static
-void numlockx_change_numlock_state( bool set )
-{
-	if( !X11Helper::xkbSupported(NULL) ) {
-    	kError() << "Failed to set numlock: xkb is not supported";
-    	return;
-	}
-
-	if( ! xkb_set_numlock(set) ) {
-    	kError() << "Failed to set numlock: XkbLockModifiers request hasn't been sent";
-	}
-}
-
 // This code is taken from xset utility from XFree 4.3 (http://www.xfree86.org/)
 
 static
@@ -177,6 +121,6 @@
 
 	int numlockState = config.readEntry( "NumLock", 2 );
 	if( numlockState != 2 ) {
-		numlockx_change_numlock_state( numlockState == 0 );
+		numlockx_change_numlock_state(QX11Info::display(), numlockState == 0 );
 	}
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic