Style cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18687 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,19 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
|
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
* Keyboard input server device addon
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "KeyboardInputDevice.h"
|
#include "KeyboardInputDevice.h"
|
||||||
#include "kb_mouse_driver.h"
|
#include "kb_mouse_driver.h"
|
||||||
|
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <NodeMonitor.h>
|
#include <NodeMonitor.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
FILE *KeyboardInputDevice::sLogFile = NULL;
|
FILE *KeyboardInputDevice::sLogFile = NULL;
|
||||||
@@ -26,7 +28,7 @@ const static char *kKeyboardDevicesDirectory = "/dev/input/keyboard";
|
|||||||
const static char *kKeyboardDevicesDirectoryPS2 = "input/keyboard/at";
|
const static char *kKeyboardDevicesDirectoryPS2 = "input/keyboard/at";
|
||||||
const static char *kKeyboardDevicesDirectoryUSB = "input/keyboard/usb";
|
const static char *kKeyboardDevicesDirectoryUSB = "input/keyboard/usb";
|
||||||
|
|
||||||
const uint32 at_keycode_map[] = {
|
const static uint32 kATKeycodeMap[] = {
|
||||||
0x1, // Esc
|
0x1, // Esc
|
||||||
0x12, // 1
|
0x12, // 1
|
||||||
0x13, // 2
|
0x13, // 2
|
||||||
@@ -329,10 +331,38 @@ instantiate_input_device()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_short_name(const char *longName)
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
BString string(longName);
|
||||||
|
BString name;
|
||||||
|
|
||||||
|
int32 slash = string.FindLast("/");
|
||||||
|
string.CopyInto(name, slash + 1, string.Length() - slash);
|
||||||
|
int32 index = atoi(name.String()) + 1;
|
||||||
|
|
||||||
|
int32 previousSlash = string.FindLast("/", slash);
|
||||||
|
string.CopyInto(name, previousSlash + 1, slash - previousSlash - 1);
|
||||||
|
|
||||||
|
// some special handling so that we get "USB" and "AT" instead of "usb"/"at"
|
||||||
|
if (name.Length() < 4)
|
||||||
|
name.ToUpper();
|
||||||
|
else
|
||||||
|
name.Capitalize();
|
||||||
|
|
||||||
|
name << " Keyboard " << index;
|
||||||
|
|
||||||
|
return strdup(name.String());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
KeyboardInputDevice::KeyboardInputDevice()
|
KeyboardInputDevice::KeyboardInputDevice()
|
||||||
: fTMWindow(NULL)
|
: fTMWindow(NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (sLogFile == NULL)
|
if (sLogFile == NULL)
|
||||||
sLogFile = fopen("/var/log/keyboard_device_log.log", "a");
|
sLogFile = fopen("/var/log/keyboard_device_log.log", "a");
|
||||||
@@ -351,8 +381,9 @@ KeyboardInputDevice::~KeyboardInputDevice()
|
|||||||
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
|
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
|
||||||
|
|
||||||
int count = fDevices.CountItems();
|
int count = fDevices.CountItems();
|
||||||
while (count-- > 0)
|
while (count-- > 0) {
|
||||||
delete (keyboard_device *)fDevices.RemoveItem((int32)0);
|
delete (keyboard_device *)fDevices.RemoveItem((int32)0);
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
fclose(sLogFile);
|
fclose(sLogFile);
|
||||||
@@ -364,9 +395,9 @@ status_t
|
|||||||
KeyboardInputDevice::SystemShuttingDown()
|
KeyboardInputDevice::SystemShuttingDown()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (fTMWindow) {
|
if (fTMWindow)
|
||||||
fTMWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
|
fTMWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
|
||||||
}
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,14 +418,12 @@ KeyboardInputDevice::InitFromSettings(void *cookie, uint32 opcode)
|
|||||||
LOG_ERR("error when KB_SET_KEY_REPEAT_RATE, fd:%d\n", device->fd);
|
LOG_ERR("error when KB_SET_KEY_REPEAT_RATE, fd:%d\n", device->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opcode == 0
|
if (opcode == 0 || opcode == B_KEY_REPEAT_DELAY_CHANGED) {
|
||||||
|| opcode == B_KEY_REPEAT_DELAY_CHANGED) {
|
|
||||||
|
|
||||||
if (get_key_repeat_delay(&device->settings.key_repeat_delay) != B_OK)
|
if (get_key_repeat_delay(&device->settings.key_repeat_delay) != B_OK)
|
||||||
LOG_ERR("error when get_key_repeat_delay\n");
|
LOG_ERR("error when get_key_repeat_delay\n");
|
||||||
else
|
else if (ioctl(device->fd, KB_SET_KEY_REPEAT_DELAY,
|
||||||
if (ioctl(device->fd, KB_SET_KEY_REPEAT_DELAY, &device->settings.key_repeat_delay)!=B_OK)
|
&device->settings.key_repeat_delay)!=B_OK)
|
||||||
LOG_ERR("error when KB_SET_KEY_REPEAT_DELAY, fd:%d\n", device->fd);
|
LOG_ERR("error when KB_SET_KEY_REPEAT_DELAY, fd:%d\n", device->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opcode == 0
|
if (opcode == 0
|
||||||
@@ -413,6 +442,7 @@ status_t
|
|||||||
KeyboardInputDevice::InitCheck()
|
KeyboardInputDevice::InitCheck()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
// TODO: this doesn't belong here!
|
||||||
RecursiveScan(kKeyboardDevicesDirectory);
|
RecursiveScan(kKeyboardDevicesDirectory);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -437,10 +467,11 @@ KeyboardInputDevice::Start(const char *name, void *cookie)
|
|||||||
|
|
||||||
device->active = true;
|
device->active = true;
|
||||||
device->device_watcher = spawn_thread(DeviceWatcher, threadName,
|
device->device_watcher = spawn_thread(DeviceWatcher, threadName,
|
||||||
kKeyboardThreadPriority, device);
|
kKeyboardThreadPriority, device);
|
||||||
|
if (device->device_watcher < B_OK)
|
||||||
|
return device->device_watcher;
|
||||||
|
|
||||||
resume_thread(device->device_watcher);
|
resume_thread(device->device_watcher);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +506,7 @@ KeyboardInputDevice::Stop(const char *name, void *cookie)
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
KeyboardInputDevice::Control(const char *name, void *cookie,
|
KeyboardInputDevice::Control(const char *name, void *cookie,
|
||||||
uint32 command, BMessage *message)
|
uint32 command, BMessage *message)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
LOG("Control(%s, code: %lu)\n", name, command);
|
LOG("Control(%s, code: %lu)\n", name, command);
|
||||||
@@ -499,11 +530,10 @@ KeyboardInputDevice::HandleMonitor(BMessage *message)
|
|||||||
if ((status = message->FindInt32("opcode", &opcode)) < B_OK)
|
if ((status = message->FindInt32("opcode", &opcode)) < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if ((opcode != B_ENTRY_CREATED)
|
if (opcode != B_ENTRY_CREATED
|
||||||
&& (opcode != B_ENTRY_REMOVED))
|
&& opcode != B_ENTRY_REMOVED)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
|
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
BPath path;
|
BPath path;
|
||||||
dev_t device;
|
dev_t device;
|
||||||
@@ -544,9 +574,7 @@ KeyboardInputDevice::AddDevice(const char *path)
|
|||||||
device->device_watcher = -1;
|
device->device_watcher = -1;
|
||||||
device->active = false;
|
device->active = false;
|
||||||
device->owner = this;
|
device->owner = this;
|
||||||
device->isAT = false;
|
device->isAT = strstr(device->path, "keyboard/at") != NULL;
|
||||||
if (strstr(device->path, "keyboard/at") != NULL)
|
|
||||||
device->isAT = true;
|
|
||||||
|
|
||||||
input_device_ref *devices[2];
|
input_device_ref *devices[2];
|
||||||
devices[0] = &device->device_ref;
|
devices[0] = &device->device_ref;
|
||||||
@@ -598,194 +626,164 @@ KeyboardInputDevice::DeviceWatcher(void *arg)
|
|||||||
LOG("%s\n", __PRETTY_FUNCTION__);
|
LOG("%s\n", __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
while (dev->active) {
|
while (dev->active) {
|
||||||
|
if (ioctl(dev->fd, KB_READ, &buffer) != B_OK)
|
||||||
if (ioctl(dev->fd, KB_READ, &buffer) != B_OK) {
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
uint32 keycode = 0;
|
||||||
|
bool isKeyDown = false;
|
||||||
|
bigtime_t timestamp = 0;
|
||||||
|
|
||||||
|
LOG("KB_READ :");
|
||||||
|
if (dev->isAT) {
|
||||||
|
at_kbd_io *at_kbd = (at_kbd_io *)buffer;
|
||||||
|
if (at_kbd->scancode > 0)
|
||||||
|
keycode = kATKeycodeMap[at_kbd->scancode-1];
|
||||||
|
isKeyDown = at_kbd->is_keydown;
|
||||||
|
timestamp = at_kbd->timestamp;
|
||||||
|
LOG(" %02x", at_kbd->scancode);
|
||||||
|
} else {
|
||||||
|
raw_key_info *raw_kbd = (raw_key_info *)buffer;
|
||||||
|
isKeyDown = raw_kbd->is_keydown;
|
||||||
|
timestamp = raw_kbd->timestamp;
|
||||||
|
keycode = raw_kbd->be_keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 keycode = 0;
|
if (keycode == 0)
|
||||||
bool is_keydown = false;
|
continue;
|
||||||
bigtime_t timestamp = 0;
|
|
||||||
|
|
||||||
LOG("KB_READ :");
|
LOG(" %Ld, %02x, %02lx\n", timestamp, isKeyDown, keycode);
|
||||||
if (dev->isAT) {
|
|
||||||
at_kbd_io *at_kbd = (at_kbd_io *)buffer;
|
|
||||||
if (at_kbd->scancode>0)
|
|
||||||
keycode = at_keycode_map[at_kbd->scancode-1];
|
|
||||||
is_keydown = at_kbd->is_keydown;
|
|
||||||
timestamp = at_kbd->timestamp;
|
|
||||||
LOG(" %02x", at_kbd->scancode);
|
|
||||||
} else {
|
|
||||||
raw_key_info *raw_kbd = (raw_key_info *)buffer;
|
|
||||||
is_keydown = raw_kbd->is_keydown;
|
|
||||||
timestamp = raw_kbd->timestamp;
|
|
||||||
keycode = raw_kbd->be_keycode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keycode == 0)
|
if (isKeyDown
|
||||||
continue;
|
&& (keycode == 0x68) ) { // MENU KEY for OpenTracker 5.2.0+
|
||||||
|
bool nokey = true;
|
||||||
LOG(" %Ld, %02x, %02lx\n", timestamp, is_keydown, keycode);
|
for (int32 i = 0; i < 16; i++) {
|
||||||
|
if (states[i] != 0) {
|
||||||
if (is_keydown
|
nokey = false;
|
||||||
&& (keycode == 0x68) ) { // MENU KEY for OpenTracker 5.2.0+
|
break;
|
||||||
bool nokey = true;
|
|
||||||
for (int32 i=0; i<16; i++)
|
|
||||||
if (states[i] != 0) {
|
|
||||||
nokey = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nokey) {
|
|
||||||
BMessenger msger("application/x-vnd.Be-TSKB");
|
|
||||||
if (msger.IsValid())
|
|
||||||
msger.SendMessage('BeMn');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_keydown)
|
if (nokey) {
|
||||||
states[(keycode)>>3] |= (1 << (7 - (keycode & 0x7)));
|
BMessenger msger("application/x-vnd.Be-TSKB");
|
||||||
|
if (msger.IsValid())
|
||||||
|
msger.SendMessage('BeMn');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isKeyDown)
|
||||||
|
states[(keycode)>>3] |= (1 << (7 - (keycode & 0x7)));
|
||||||
|
else
|
||||||
|
states[(keycode)>>3] &= (!(1 << (7 - (keycode & 0x7))));
|
||||||
|
|
||||||
|
if (isKeyDown
|
||||||
|
&& keycode == 0x34 // DELETE KEY
|
||||||
|
&& (states[0x5c >> 3] & (1 << (7 - (0x5c & 0x7))))
|
||||||
|
&& (states[0x5d >> 3] & (1 << (7 - (0x5d & 0x7))))) {
|
||||||
|
LOG("TeamMonitor called\n");
|
||||||
|
|
||||||
|
// show the team monitor
|
||||||
|
if (!dev->owner->fTMWindow)
|
||||||
|
dev->owner->fTMWindow = new TMWindow();
|
||||||
|
|
||||||
|
dev->owner->fTMWindow->Enable();
|
||||||
|
|
||||||
|
// cancel timer only for R5
|
||||||
|
if (ioctl(dev->fd, KB_CANCEL_CONTROL_ALT_DEL, NULL) == B_OK)
|
||||||
|
LOG("KB_CANCEL_CONTROL_ALT_DEL : OK\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 modifiers = keymap->Modifier(keycode);
|
||||||
|
if (modifiers
|
||||||
|
&& (!(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK))
|
||||||
|
|| isKeyDown)) {
|
||||||
|
BMessage *msg = new BMessage;
|
||||||
|
msg->AddInt64("when", timestamp);
|
||||||
|
msg->what = B_MODIFIERS_CHANGED;
|
||||||
|
msg->AddInt32("be:old_modifiers", dev->modifiers);
|
||||||
|
if ((isKeyDown && !(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK)))
|
||||||
|
|| (isKeyDown && !(dev->modifiers & modifiers)))
|
||||||
|
dev->modifiers |= modifiers;
|
||||||
else
|
else
|
||||||
states[(keycode)>>3] &= (!(1 << (7 - (keycode & 0x7))));
|
dev->modifiers &= ~modifiers;
|
||||||
|
|
||||||
if (is_keydown
|
msg->AddInt32("modifiers", dev->modifiers);
|
||||||
&& (keycode == 0x34) // DELETE KEY
|
msg->AddData("states", B_UINT8_TYPE, states, 16);
|
||||||
&& (states[0x5c >> 3] & (1 << (7 - (0x5c & 0x7))))
|
if (dev->owner->EnqueueMessage(msg)!=B_OK)
|
||||||
&& (states[0x5d >> 3] & (1 << (7 - (0x5d & 0x7))))) {
|
delete msg;
|
||||||
|
|
||||||
LOG("TeamMonitor called\n");
|
if (modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK))
|
||||||
|
dev->owner->SetLeds(dev);
|
||||||
|
}
|
||||||
|
|
||||||
// show the team monitor
|
char *str = NULL, *str2 = NULL;
|
||||||
if (!dev->owner->fTMWindow)
|
int32 numBytes = 0, numBytes2 = 0;
|
||||||
dev->owner->fTMWindow = new TMWindow();
|
uint8 newDeadKey = 0;
|
||||||
|
|
||||||
dev->owner->fTMWindow->Enable();
|
if (activeDeadKey == 0)
|
||||||
|
newDeadKey = keymap->IsDeadKey(keycode, dev->modifiers);
|
||||||
|
|
||||||
// cancel timer only for R5
|
// new dead key behaviour
|
||||||
if (ioctl(dev->fd, KB_CANCEL_CONTROL_ALT_DEL, NULL) == B_OK)
|
#if 0
|
||||||
LOG("KB_CANCEL_CONTROL_ALT_DEL : OK\n");
|
if (newDeadKey == 0) {
|
||||||
}
|
keymap->GetChars(keycode, dev->modifiers, activeDeadKey, &str, &numBytes);
|
||||||
|
keymap->GetChars(keycode, 0, 0, &str2, &numBytes2);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32 modifiers = keymap->Modifier(keycode);
|
// R5-like dead key behaviour
|
||||||
if (modifiers
|
if (newDeadKey == 0) {
|
||||||
&& ( !(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK))
|
keymap->GetChars(keycode, dev->modifiers, activeDeadKey, &str, &numBytes);
|
||||||
|| is_keydown)) {
|
keymap->GetChars(keycode, 0, 0, &str2, &numBytes2);
|
||||||
BMessage *msg = new BMessage;
|
|
||||||
msg->AddInt64("when", timestamp);
|
|
||||||
msg->what = B_MODIFIERS_CHANGED;
|
|
||||||
msg->AddInt32("be:old_modifiers", dev->modifiers);
|
|
||||||
if ((is_keydown && !(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK)))
|
|
||||||
|| (is_keydown && !(dev->modifiers & modifiers)))
|
|
||||||
dev->modifiers |= modifiers;
|
|
||||||
else
|
|
||||||
dev->modifiers &= ~modifiers;
|
|
||||||
|
|
||||||
msg->AddInt32("modifiers", dev->modifiers);
|
BMessage *msg = new BMessage;
|
||||||
msg->AddData("states", B_UINT8_TYPE, states, 16);
|
if (numBytes > 0)
|
||||||
if (dev->owner->EnqueueMessage(msg)!=B_OK)
|
msg->what = isKeyDown ? B_KEY_DOWN : B_KEY_UP;
|
||||||
delete msg;
|
else
|
||||||
|
msg->what = isKeyDown ? B_UNMAPPED_KEY_DOWN : B_UNMAPPED_KEY_UP;
|
||||||
|
|
||||||
if (modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK))
|
msg->AddInt64("when", timestamp);
|
||||||
dev->owner->SetLeds(dev);
|
msg->AddInt32("key", keycode);
|
||||||
}
|
msg->AddInt32("modifiers", dev->modifiers);
|
||||||
|
msg->AddData("states", B_UINT8_TYPE, states, 16);
|
||||||
|
if (numBytes > 0) {
|
||||||
|
for (int i = 0; i < numBytes; i++) {
|
||||||
|
msg->AddInt8("byte", (int8)str[i]);
|
||||||
|
}
|
||||||
|
msg->AddString("bytes", str);
|
||||||
|
|
||||||
char *str = NULL, *str2 = NULL;
|
if (numBytes2 <= 0) {
|
||||||
int32 numBytes = 0, numBytes2 = 0;
|
numBytes2 = 1;
|
||||||
uint8 newDeadKey = 0;
|
delete[] str2;
|
||||||
|
str2 = str;
|
||||||
if (activeDeadKey == 0) {
|
|
||||||
newDeadKey = keymap->IsDeadKey(keycode, dev->modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// new dead key behaviour
|
|
||||||
/*if (newDeadKey == 0) {
|
|
||||||
keymap->GetChars(keycode, dev->modifiers, activeDeadKey, &str, &numBytes);
|
|
||||||
keymap->GetChars(keycode, 0, 0, &str2, &numBytes2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (true) {
|
|
||||||
*/
|
|
||||||
|
|
||||||
// R5-like dead key behaviour
|
|
||||||
if (newDeadKey == 0) {
|
|
||||||
keymap->GetChars(keycode, dev->modifiers, activeDeadKey, &str, &numBytes);
|
|
||||||
keymap->GetChars(keycode, 0, 0, &str2, &numBytes2);
|
|
||||||
|
|
||||||
BMessage *msg = new BMessage;
|
|
||||||
if (numBytes>0)
|
|
||||||
msg->what = is_keydown ? B_KEY_DOWN : B_KEY_UP;
|
|
||||||
else
|
|
||||||
msg->what = is_keydown ? B_UNMAPPED_KEY_DOWN : B_UNMAPPED_KEY_UP;
|
|
||||||
|
|
||||||
msg->AddInt64("when", timestamp);
|
|
||||||
msg->AddInt32("key", keycode);
|
|
||||||
msg->AddInt32("modifiers", dev->modifiers);
|
|
||||||
msg->AddData("states", B_UINT8_TYPE, states, 16);
|
|
||||||
if (numBytes>0) {
|
|
||||||
for (int i=0; i<numBytes; i++)
|
|
||||||
msg->AddInt8("byte", (int8)str[i]);
|
|
||||||
msg->AddString("bytes", str);
|
|
||||||
|
|
||||||
if (numBytes2<=0) {
|
|
||||||
numBytes2 = 1;
|
|
||||||
delete[] str2;
|
|
||||||
str2 = str;
|
|
||||||
} else
|
|
||||||
delete[] str;
|
|
||||||
|
|
||||||
if (is_keydown && (lastKeyCode == keycode)) {
|
|
||||||
repeatCount++;
|
|
||||||
msg->AddInt32("be:key_repeat", repeatCount);
|
|
||||||
} else
|
|
||||||
repeatCount = 1;
|
|
||||||
} else
|
} else
|
||||||
delete[] str;
|
delete[] str;
|
||||||
|
|
||||||
if (numBytes2>0)
|
if (isKeyDown && lastKeyCode == keycode) {
|
||||||
msg->AddInt32("raw_char", (uint32)((uint8)str2[0] & 0x7f));
|
repeatCount++;
|
||||||
delete[] str2;
|
msg->AddInt32("be:key_repeat", repeatCount);
|
||||||
|
} else
|
||||||
|
repeatCount = 1;
|
||||||
|
} else
|
||||||
|
delete[] str;
|
||||||
|
|
||||||
if (dev->owner->EnqueueMessage(msg)!=B_OK)
|
if (numBytes2 > 0)
|
||||||
|
msg->AddInt32("raw_char", (uint32)((uint8)str2[0] & 0x7f));
|
||||||
|
delete[] str2;
|
||||||
|
|
||||||
|
if (dev->owner->EnqueueMessage(msg) != B_OK)
|
||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_keydown && !modifiers) {
|
if (!isKeyDown && !modifiers)
|
||||||
activeDeadKey = newDeadKey;
|
activeDeadKey = newDeadKey;
|
||||||
}
|
|
||||||
lastKeyCode = keycode;
|
lastKeyCode = keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static char *
|
|
||||||
GetShortName(const char *longName)
|
|
||||||
{
|
|
||||||
CALLED();
|
|
||||||
BString string(longName);
|
|
||||||
BString name;
|
|
||||||
|
|
||||||
int32 slash = string.FindLast("/");
|
|
||||||
string.CopyInto(name, slash + 1, string.Length() - slash);
|
|
||||||
int32 index = atoi(name.String()) + 1;
|
|
||||||
|
|
||||||
int32 previousSlash = string.FindLast("/", slash);
|
|
||||||
string.CopyInto(name, previousSlash + 1, slash - previousSlash - 1);
|
|
||||||
|
|
||||||
// some special handling so that we get "USB" and "AT" instead of "usb"/"at"
|
|
||||||
if (name.Length() < 4)
|
|
||||||
name.ToUpper();
|
|
||||||
else
|
|
||||||
name.Capitalize();
|
|
||||||
|
|
||||||
name << " Keyboard " << index;
|
|
||||||
|
|
||||||
return strdup(name.String());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardInputDevice::RecursiveScan(const char *directory)
|
KeyboardInputDevice::RecursiveScan(const char *directory)
|
||||||
{
|
{
|
||||||
@@ -806,7 +804,7 @@ KeyboardInputDevice::RecursiveScan(const char *directory)
|
|||||||
void
|
void
|
||||||
KeyboardInputDevice::SetLeds(keyboard_device *device)
|
KeyboardInputDevice::SetLeds(keyboard_device *device)
|
||||||
{
|
{
|
||||||
if (device->fd<0)
|
if (device->fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32 locks = device->modifiers;
|
uint32 locks = device->modifiers;
|
||||||
@@ -824,10 +822,10 @@ KeyboardInputDevice::SetLeds(keyboard_device *device)
|
|||||||
|
|
||||||
|
|
||||||
keyboard_device::keyboard_device(const char *path)
|
keyboard_device::keyboard_device(const char *path)
|
||||||
// todo: initialize other members
|
|
||||||
{
|
{
|
||||||
|
// todo: initialize other members
|
||||||
strcpy(this->path, path);
|
strcpy(this->path, path);
|
||||||
device_ref.name = GetShortName(path);
|
device_ref.name = get_short_name(path);
|
||||||
device_ref.type = B_KEYBOARD_DEVICE;
|
device_ref.type = B_KEYBOARD_DEVICE;
|
||||||
device_ref.cookie = this;
|
device_ref.cookie = this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user