2
* Copyright (C) 2010 Andriy Rysin (rysin@kde.org)
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include <kconfiggroup.h>
21
#include <ksharedconfig.h>
23
#include <QtGui/QX11Info>
24
#include <QtGui/QCursor> // WTF? - otherwise compiler complains
30
#include "x11_helper.h"
34
extern "C" void numlockx_change_numlock_state(Display* dpy, int state);
36
#include <X11/XKBlib.h>
37
#include <X11/keysym.h>
40
// This code is taken from xset utility from XFree 4.3 (http://www.xfree86.org/)
43
void set_repeatrate(int delay, double rate)
45
if( !X11Helper::xkbSupported(NULL) ) {
46
kError() << "Failed to set keyboard repeat rate: xkb is not supported";
50
XkbDescPtr xkb = XkbAllocKeyboard();
52
Display* dpy = QX11Info::display();
53
int res = XkbGetControls(dpy, XkbRepeatKeysMask, xkb);
54
xkb->ctrls->repeat_delay = delay;
55
xkb->ctrls->repeat_interval = (int)floor(1000/rate + 0.5);
56
res = XkbSetControls(dpy, XkbRepeatKeysMask, xkb);
62
int set_volume(int clickVolumePercent, TriState keyboardRepeatMode)
65
XKeyboardControl kbdc;
67
XGetKeyboardControl(QX11Info::display(), &kbd);
70
if( clickVolumePercent != -1 ) {
71
flags |= KBKeyClickPercent;
72
kbdc.key_click_percent = clickVolumePercent;
74
if( keyboardRepeatMode != STATE_UNCHANGED ) {
75
flags |= KBAutoRepeatMode;
76
kbdc.auto_repeat_mode = (keyboardRepeatMode==STATE_ON ? AutoRepeatModeOn : AutoRepeatModeOff);
79
return XChangeKeyboardControl(QX11Info::display(), flags, &kbdc);
82
void init_keyboard_hardware()
84
KConfigGroup config(KSharedConfig::openConfig( "kcminputrc" ), "Keyboard");
86
QString keyRepeatStr = config.readEntry("KeyboardRepeating", TriStateHelper::getString(STATE_ON));
87
TriState keyRepeat = STATE_UNCHANGED;
88
if( keyRepeatStr == "true" || keyRepeatStr == TriStateHelper::getString(STATE_ON) ) {
91
else if( keyRepeatStr == "false" || keyRepeatStr == TriStateHelper::getString(STATE_OFF) ) {
92
keyRepeat = STATE_OFF;
95
int clickVolumePercent = config.readEntry("ClickVolume", -1);
96
if( clickVolumePercent != -1 && keyRepeat != STATE_UNCHANGED ) {
97
set_volume(clickVolumePercent, keyRepeat);
100
if( keyRepeat == STATE_ON ) {
101
int delay_ = config.readEntry("RepeatDelay", 250);
102
double rate_ = config.readEntry("RepeatRate", 30.);
103
set_repeatrate(delay_, rate_);
107
TriState numlockState = TriStateHelper::getTriState( config.readEntry( "NumLock", TriStateHelper::getInt(STATE_UNCHANGED) ) );
108
if( numlockState != STATE_UNCHANGED ) {
109
numlockx_change_numlock_state(QX11Info::display(), numlockState == STATE_ON );