Support for LEDS

Support for keymap reloading


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8992 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-09-17 12:07:21 +00:00
parent 98ecc9715d
commit 421f4885ed
4 changed files with 88 additions and 32 deletions

View File

@ -357,17 +357,6 @@ const uint32 at_keycode_map[] = {
FILE *KeyboardInputDevice::sLogFile = NULL;
struct keyboard_device {
KeyboardInputDevice *owner;
input_device_ref device_ref;
char path[B_PATH_NAME_LENGTH];
int fd;
thread_id device_watcher;
kb_settings settings;
bool active;
bool isAT;
};
extern "C"
BInputServerDevice *
instantiate_input_device()
@ -407,17 +396,33 @@ KeyboardInputDevice::InitFromSettings(void *cookie, uint32 opcode)
keyboard_device *device = (keyboard_device *)cookie;
if (get_key_repeat_rate(&device->settings.key_repeat_rate) != B_OK)
LOG_ERR("error when get_key_repeat_rate\n");
else
if (ioctl(device->fd, kSetKeyRepeatRate, &device->settings.key_repeat_rate)!=B_OK)
LOG_ERR("error when kSetKeyRepeatRate, fd:%li\n", device->fd);
if (opcode == 0
|| opcode == B_KEY_REPEAT_RATE_CHANGED) {
if (get_key_repeat_rate(&device->settings.key_repeat_rate) != B_OK)
LOG_ERR("error when get_key_repeat_rate\n");
else
if (ioctl(device->fd, kSetKeyRepeatRate, &device->settings.key_repeat_rate)!=B_OK)
LOG_ERR("error when kSetKeyRepeatRate, fd:%li\n", device->fd);
}
if (opcode == 0
|| opcode == B_KEY_REPEAT_DELAY_CHANGED) {
if (get_key_repeat_delay(&device->settings.key_repeat_delay) != B_OK)
LOG_ERR("error when get_key_repeat_delay\n");
else
if (ioctl(device->fd, kSetKeyRepeatDelay, &device->settings.key_repeat_delay)!=B_OK)
LOG_ERR("error when kSetKeyRepeatDelay, fd:%li\n", device->fd);
}
if (opcode == 0
|| opcode == B_KEY_MAP_CHANGED
|| opcode == B_KEY_LOCKS_CHANGED) {
fKeymap.LoadCurrent();
SetLeds(device);
device->modifiers = fKeymap.Locks();
}
if (get_key_repeat_delay(&device->settings.key_repeat_delay) != B_OK)
LOG_ERR("error when get_key_repeat_delay\n");
else
if (ioctl(device->fd, kSetKeyRepeatDelay, &device->settings.key_repeat_delay)!=B_OK)
LOG_ERR("error when kSetKeyRepeatDelay, fd:%li\n", device->fd);
return B_OK;
}
@ -592,7 +597,6 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
CALLED();
keyboard_device *dev = (keyboard_device *)arg;
uint8 buffer[16];
uint32 currentModifiers = 0;
uint8 activeDeadKey = 0;
Keymap *keymap = &dev->owner->fKeymap;
uint32 lastKeyCode = 0;
@ -669,13 +673,13 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
BMessage *msg = new BMessage;
msg->AddInt64("when", timestamp);
msg->what = B_MODIFIERS_CHANGED;
msg->AddInt32("be:old_modifiers", currentModifiers);
msg->AddInt32("be:old_modifiers", dev->modifiers);
if ((is_keydown && !(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK)))
|| (is_keydown && !(currentModifiers & modifiers)))
currentModifiers |= modifiers;
|| (is_keydown && !(dev->modifiers & modifiers)))
dev->modifiers |= modifiers;
else
currentModifiers &= !modifiers;
msg->AddInt32("modifiers", currentModifiers);
dev->modifiers &= !modifiers;
msg->AddInt32("modifiers", dev->modifiers);
msg->AddData("states", B_UINT8_TYPE, states, 16);
if (dev->owner->EnqueueMessage(msg)!=B_OK)
delete msg;
@ -686,13 +690,13 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
uint8 newDeadKey = 0;
if (activeDeadKey == 0) {
newDeadKey = keymap->IsDeadKey(keycode, currentModifiers);
newDeadKey = keymap->IsDeadKey(keycode, dev->modifiers);
}
// new dead key behaviour
/*if (newDeadKey == 0) {
keymap->GetChars(keycode, currentModifiers, activeDeadKey, &str, &numBytes);
keymap->GetChars(keycode, dev->modifiers, activeDeadKey, &str, &numBytes);
keymap->GetChars(keycode, 0, 0, &str2, &numBytes2);
}
@ -701,7 +705,7 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
// R5-like dead key behaviour
if (newDeadKey == 0) {
keymap->GetChars(keycode, currentModifiers, activeDeadKey, &str, &numBytes);
keymap->GetChars(keycode, dev->modifiers, activeDeadKey, &str, &numBytes);
keymap->GetChars(keycode, 0, 0, &str2, &numBytes2);
BMessage *msg = new BMessage;
@ -712,7 +716,7 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
msg->AddInt64("when", timestamp);
msg->AddInt32("key", keycode);
msg->AddInt32("modifiers", currentModifiers);
msg->AddInt32("modifiers", dev->modifiers);
msg->AddData("states", B_UINT8_TYPE, states, 16);
if (numBytes>0) {
for (int i=0; i<numBytes; i++)
@ -786,3 +790,23 @@ KeyboardInputDevice::RecursiveScan(const char *directory)
AddDevice(path.Path());
}
}
void
KeyboardInputDevice::SetLeds(keyboard_device *device)
{
if (device->fd<0)
return;
uint32 locks = device->owner->fKeymap.Locks();
char lock_io[3];
memset(lock_io, 0, sizeof(lock_io));
if (locks & B_NUM_LOCK)
lock_io[0] = 1;
if (locks & B_CAPS_LOCK)
lock_io[1] = 1;
if (locks & B_SCROLL_LOCK)
lock_io[2] = 1;
ioctl(device->fd, kSetLeds, &lock_io);
}

View File

@ -33,6 +33,20 @@
#include <stdio.h>
#include "kb_mouse_driver.h"
class KeyboardInputDevice;
struct keyboard_device {
KeyboardInputDevice *owner;
input_device_ref device_ref;
char path[B_PATH_NAME_LENGTH];
int fd;
thread_id device_watcher;
kb_settings settings;
bool active;
bool isAT;
uint32 modifiers;
};
class KeyboardInputDevice : public BInputServerDevice {
public:
@ -59,6 +73,8 @@ private:
static int32 DeviceWatcher(void *arg);
static char *GetShortName(const char *longName);
void SetLeds(keyboard_device *device);
BList fDevices;
Keymap fKeymap;
};

View File

@ -354,3 +354,18 @@ Keymap::GetChars(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey, char** c
(*chars)[*numBytes] = 0;
}
status_t
Keymap::LoadCurrent()
{
key_map *keys = NULL;
get_key_map(&keys, &fChars);
if (!keys) {
fprintf(stderr, "error while getting current keymap!\n");
return B_ERROR;
}
memcpy(&fKeys, keys, sizeof(fKeys));
delete keys;
return B_OK;
}

View File

@ -29,10 +29,11 @@ public:
uint8 IsDeadKey(uint32 keyCode, uint32 modifiers);
bool IsDeadSecondKey(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey);
void GetChars(uint32 keyCode, uint32 modifiers, uint8 activeDeadKey, char** chars, int32* numBytes);
uint32 Locks() { return fKeys.lock_settings; };
status_t LoadCurrent();
private:
char *fChars;
key_map fKeys;
//uint32 fCharsSize;
};