[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-08-31 0:27:23
Message-ID: 20100831002723.27E67AC857 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1170173 by rysin:
improve keyboard hardware settings code (try at BUG 248250)
M +52 -67 keyboard_hardware.cpp
M +4 -2 xinput_helper.cpp
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/keyboard_hardware.cpp \
#1170172:1170173 @@ -16,19 +16,20 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <config-workspace.h>
-#include <config-X11.h>
-
+#include <kdebug.h>
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <QtGui/QX11Info>
+#include <QtGui/QCursor> // WTF? - otherwise compiler complains
#include <X11/Xlib.h>
#include <math.h>
+#include "x11_helper.h"
+
/*
Originally comes from NumLockX http://dforce.sh.cvut.cz/~seli/en/numlockx
@@ -60,29 +61,16 @@
#include <X11/XKBlib.h>
#include <X11/keysym.h>
-/* the XKB stuff is based on code created by Oswald Buddenhagen <ossi@kde.org> */
-int xkb_init()
- {
- int xkb_opcode, xkb_event, xkb_error;
- int xkb_lmaj = XkbMajorVersion;
- int xkb_lmin = XkbMinorVersion;
- return XkbLibraryVersion( &xkb_lmaj, &xkb_lmin )
- && XkbQueryExtension( QX11Info::display(), &xkb_opcode, &xkb_event, &xkb_error,
- &xkb_lmaj, &xkb_lmin );
- }
+static
unsigned int xkb_mask_modifier( XkbDescPtr xkb, const char *name )
{
- int i;
if( !xkb || !xkb->names )
return 0;
- for( i = 0;
- i < XkbNumVirtualMods;
- i++ )
- {
+
+ for(int i = 0; i < XkbNumVirtualMods; i++ ) {
char* modStr = XGetAtomName( xkb->dpy, xkb->names->vmods[i] );
- if( modStr != NULL && strcmp(name, modStr) == 0 )
- {
+ if( modStr != NULL && strcmp(name, modStr) == 0 ) {
unsigned int mask;
XkbVirtualModsToReal( xkb, 1 << i, &mask );
return mask;
@@ -91,74 +79,60 @@
return 0;
}
+static
unsigned int xkb_numlock_mask()
{
XkbDescPtr xkb;
- if(( xkb = XkbGetKeyboard( QX11Info::display(), XkbAllComponentsMask, \
XkbUseCoreKbd )) != NULL )
- {
+ if(( xkb = XkbGetKeyboard( QX11Info::display(), XkbAllComponentsMask, XkbUseCoreKbd \
)) != NULL ) { unsigned int mask = xkb_mask_modifier( xkb, "NumLock" );
XkbFreeKeyboard( xkb, 0, True );
return mask;
}
- return 0;
+ else {
+ kError() << "Failed to set numlock: failed to get keyboard";
}
-
-int xkb_set_on()
- {
- unsigned int mask;
- if( !xkb_init())
return 0;
- mask = xkb_numlock_mask();
- if( mask == 0 )
- return 0;
- XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd, mask, mask);
- return 1;
}
-int xkb_set_off()
+static
+int xkb_set_numlock(int set)
{
- unsigned int mask;
- if( !xkb_init())
+ unsigned int mask = xkb_numlock_mask();
+ if( mask == 0 ) {
+ kError() << "Failed to set numlock: numlock mask is 0";
return 0;
- mask = xkb_numlock_mask();
- if( mask == 0 )
- return 0;
- XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd, mask, 0);
- return 1;
}
-void numlock_set_on()
- {
- if( xkb_set_on())
- return;
+ unsigned int values = set ? mask : 0;
+ return XkbLockModifiers ( QX11Info::display(), XkbUseCoreKbd, mask, values);
}
-void numlock_set_off()
+static
+void numlockx_change_numlock_state( bool set )
{
- if( xkb_set_off())
+ if( !X11Helper::xkbSupported(NULL) ) {
+ kError() << "Failed to set numlock: xkb is not supported";
return;
}
-void numlockx_change_numlock_state( bool set_P )
- {
- if( set_P )
- numlock_set_on();
- else
- numlock_set_off();
+ 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
void set_repeatrate(int delay, double rate)
{
- Display* dpy = QX11Info::display();
- int xkbmajor = XkbMajorVersion, xkbminor = XkbMinorVersion;
- int xkbopcode, xkbevent, xkberror;
+ if( !X11Helper::xkbSupported(NULL) ) {
+ kError() << "Failed to set keyboard repeat rate: xkb is not supported";
+ return;
+ }
- if (XkbQueryExtension(dpy, &xkbopcode, &xkbevent, &xkberror, &xkbmajor,
- &xkbminor)) {
XkbDescPtr xkb = XkbAllocKeyboard();
if (xkb) {
+ Display* dpy = QX11Info::display();
int res = XkbGetControls(dpy, XkbRepeatKeysMask, xkb);
xkb->ctrls->repeat_delay = delay;
xkb->ctrls->repeat_interval = (int)floor(1000/rate + 0.5);
@@ -166,25 +140,35 @@
return;
}
}
-}
-void init_keyboard_hardware()
+static
+void set_volume(int click_percent, bool auto_repeat_mode)
{
- KConfigGroup config(KSharedConfig::openConfig( "kcminputrc" ), "Keyboard");
-
XKeyboardState kbd;
XKeyboardControl kbdc;
XGetKeyboardControl(QX11Info::display(), &kbd);
- bool key = config.readEntry("KeyboardRepeating", true);
- kbdc.key_click_percent = config.readEntry("ClickVolume", kbd.key_click_percent);
- kbdc.auto_repeat_mode = (key ? AutoRepeatModeOn : AutoRepeatModeOff);
+ if( click_percent != -1 ) {
+ kbdc.key_click_percent = click_percent;
+ }
+ kbdc.auto_repeat_mode = (auto_repeat_mode ? AutoRepeatModeOn : AutoRepeatModeOff);
+
XChangeKeyboardControl(QX11Info::display(),
KBKeyClickPercent | KBAutoRepeatMode,
&kbdc);
+}
- if( key ) {
+void init_keyboard_hardware()
+{
+ KConfigGroup config(KSharedConfig::openConfig( "kcminputrc" ), "Keyboard");
+
+ bool key_repeat = config.readEntry("KeyboardRepeating", true);
+ int click_percent = config.readEntry("ClickVolume", -1);
+
+ set_volume(click_percent, key_repeat);
+
+ if( key_repeat ) {
int delay_ = config.readEntry("RepeatDelay", 250);
double rate_ = config.readEntry("RepeatRate", 30.);
set_repeatrate(delay_, rate_);
@@ -192,6 +176,7 @@
int numlockState = config.readEntry( "NumLock", 2 );
- if( numlockState != 2 )
+ if( numlockState != 2 ) {
numlockx_change_numlock_state( numlockState == 0 );
}
+}
--- trunk/KDE/kdebase/workspace/kcontrol/keyboard/xinput_helper.cpp #1170172:1170173
@@ -91,16 +91,18 @@
int ndevices;
XDeviceInfo *devices = XListInputDevices(xdpne->display, &ndevices);
if( devices != NULL ) {
- kDebug() << "New device id:" << xdpne->deviceid;
+// kDebug() << "New device id:" << xdpne->deviceid;
for(int i=0; i<ndevices; i++) {
- kDebug() << "id:" << devices[i].id << "name:" << devices[i].name << "used as:" \
<< devices[i].use; +// kDebug() << "id:" << devices[i].id << "name:" << \
devices[i].name << "used as:" << devices[i].use; if( devices[i].id == \
xdpne->deviceid ) {
if( devices[i].use == IsXKeyboard || devices[i].use == IsXExtensionKeyboard ) \
{ newDeviceType = DEVICE_KEYBOARD;
+ kDebug() << "new keyboard device, id:" << devices[i].id << "name:" << \
devices[i].name << "used as:" << devices[i].use; break;
}
if( devices[i].use == IsXPointer || devices[i].use == IsXExtensionPointer ) {
newDeviceType = DEVICE_POINTER;
+ kDebug() << "new pointer device, id:" << devices[i].id << "name:" << \
devices[i].name << "used as:" << devices[i].use; break;
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic