* Removed the log file stuff; debug output is now using debug_printf() instead.
* Removed an inconsistency: both mouse and keyboad input device add-ons would scan /dev/input/keyboard respectively /dev/input/mouse when loaded, but then only monitor certain subdirectories from it. Now they monitor all. * Made KeyboardInputDevice::InitCheck() do what the name says, ie. nothing else. * Now uses BObjectList instead of BList, which also simplifies the code a bit. * Make use of the new BPathMonitor messages: as those contain a path, they greatly simplify their handling. * Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28242 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src add-ons input_server devices keyboard ;
|
|||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
|
|
||||||
UsePrivateHeaders input interface tracker ;
|
UsePrivateHeaders input interface shared tracker ;
|
||||||
UsePrivateSystemHeaders ;
|
UsePrivateSystemHeaders ;
|
||||||
|
|
||||||
Addon <input>keyboard :
|
Addon <input>keyboard :
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
|
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
|
||||||
|
* Copyright 2005-2008, Axel Dörfler, [email protected].
|
||||||
|
*
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "KeyboardInputDevice.h"
|
#include "KeyboardInputDevice.h"
|
||||||
#include "kb_mouse_driver.h"
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <new>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
@@ -15,23 +22,24 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include "kb_mouse_driver.h"
|
||||||
#include <new>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG
|
//#define TRACE_KEYBOARD_DEVICE
|
||||||
FILE *KeyboardInputDevice::sLogFile = NULL;
|
#ifdef TRACE_KEYBOARD_DEVICE
|
||||||
|
# define LOG(text...) debug_printf(text)
|
||||||
|
# define LOG_ERR(text...) LOG(text)
|
||||||
|
#else
|
||||||
|
# define LOG(text...) do {} while (0)
|
||||||
|
# define LOG_ERR(text...) debug_printf(text)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
|
|
||||||
const static uint32 kKeyboardThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
|
const static uint32 kKeyboardThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
|
||||||
const static char* kKeyboardDevicesDirectory = "/dev/input/keyboard";
|
const static char* kKeyboardDevicesDirectory = "/dev/input/keyboard";
|
||||||
|
|
||||||
// "/dev/" is automatically prepended by StartMonitoringDevice()
|
|
||||||
const static char *kKeyboardDevicesDirectoryPS2 = "input/keyboard/at";
|
|
||||||
const static char *kKeyboardDevicesDirectoryUSB = "input/keyboard/usb";
|
|
||||||
|
|
||||||
const static uint32 kATKeycodeMap[] = {
|
const static uint32 kATKeycodeMap[] = {
|
||||||
0x1, // Esc
|
0x1, // Esc
|
||||||
0x12, // 1
|
0x12, // 1
|
||||||
@@ -327,8 +335,7 @@ const static uint32 kATKeycodeMap[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C" BInputServerDevice*
|
||||||
BInputServerDevice *
|
|
||||||
instantiate_input_device()
|
instantiate_input_device()
|
||||||
{
|
{
|
||||||
return new(std::nothrow) KeyboardInputDevice();
|
return new(std::nothrow) KeyboardInputDevice();
|
||||||
@@ -366,31 +373,21 @@ get_short_name(const char *longName)
|
|||||||
|
|
||||||
KeyboardInputDevice::KeyboardInputDevice()
|
KeyboardInputDevice::KeyboardInputDevice()
|
||||||
:
|
:
|
||||||
fTMWindow(NULL),
|
fDevices(2, true),
|
||||||
|
fTeamMonitorWindow(NULL),
|
||||||
fKeymapLock("keymap lock")
|
fKeymapLock("keymap lock")
|
||||||
{
|
{
|
||||||
#if DEBUG
|
|
||||||
if (sLogFile == NULL)
|
|
||||||
sLogFile = fopen("/var/log/keyboard_device_log.log", "a");
|
|
||||||
#endif
|
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
|
StartMonitoringDevice(kKeyboardDevicesDirectory);
|
||||||
|
_RecursiveScan(kKeyboardDevicesDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KeyboardInputDevice::~KeyboardInputDevice()
|
KeyboardInputDevice::~KeyboardInputDevice()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
StopMonitoringDevice(kKeyboardDevicesDirectoryUSB);
|
StopMonitoringDevice(kKeyboardDevicesDirectory);
|
||||||
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
|
|
||||||
|
|
||||||
int count = fDevices.CountItems();
|
|
||||||
while (count-- > 0) {
|
|
||||||
delete (keyboard_device *)fDevices.RemoveItem((int32)0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
fclose(sLogFile);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -398,8 +395,8 @@ status_t
|
|||||||
KeyboardInputDevice::SystemShuttingDown()
|
KeyboardInputDevice::SystemShuttingDown()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (fTMWindow)
|
if (fTeamMonitorWindow)
|
||||||
fTMWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
|
fTeamMonitorWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -428,8 +425,7 @@ KeyboardInputDevice::_InitFromSettings(void *cookie, uint32 opcode)
|
|||||||
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 || opcode == B_KEY_MAP_CHANGED
|
||||||
|| opcode == B_KEY_MAP_CHANGED
|
|
||||||
|| opcode == B_KEY_LOCKS_CHANGED) {
|
|| opcode == B_KEY_LOCKS_CHANGED) {
|
||||||
BAutolock lock(fKeymapLock);
|
BAutolock lock(fKeymapLock);
|
||||||
fKeymap.LoadCurrent();
|
fKeymap.LoadCurrent();
|
||||||
@@ -445,17 +441,7 @@ status_t
|
|||||||
KeyboardInputDevice::InitCheck()
|
KeyboardInputDevice::InitCheck()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
status_t status = BInputServerDevice::InitCheck();
|
return BInputServerDevice::InitCheck();
|
||||||
if (status < B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
// TODO: this doesn't belong here!
|
|
||||||
_RecursiveScan(kKeyboardDevicesDirectory);
|
|
||||||
|
|
||||||
StartMonitoringDevice(kKeyboardDevicesDirectoryPS2);
|
|
||||||
StartMonitoringDevice(kKeyboardDevicesDirectoryUSB);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -505,9 +491,9 @@ KeyboardInputDevice::Stop(const char *name, void *cookie)
|
|||||||
wait_for_thread(device->device_watcher, &dummy);
|
wait_for_thread(device->device_watcher, &dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fTMWindow) {
|
if (fTeamMonitorWindow) {
|
||||||
fTMWindow->PostMessage(B_QUIT_REQUESTED);
|
fTeamMonitorWindow->PostMessage(B_QUIT_REQUESTED);
|
||||||
fTMWindow = NULL;
|
fTeamMonitorWindow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -535,40 +521,18 @@ status_t
|
|||||||
KeyboardInputDevice::_HandleMonitor(BMessage* message)
|
KeyboardInputDevice::_HandleMonitor(BMessage* message)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
int32 opcode = 0;
|
|
||||||
status_t status;
|
|
||||||
if ((status = message->FindInt32("opcode", &opcode)) < B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
if (opcode != B_ENTRY_CREATED
|
const char* path;
|
||||||
&& opcode != B_ENTRY_REMOVED)
|
int32 opcode;
|
||||||
return B_OK;
|
if (message->FindInt32("opcode", &opcode) != B_OK
|
||||||
|
|| opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED
|
||||||
BEntry entry;
|
|| message->FindString("path", &path) != B_OK)
|
||||||
BPath path;
|
return B_BAD_VALUE;
|
||||||
dev_t device;
|
|
||||||
ino_t directory;
|
|
||||||
const char *name = NULL;
|
|
||||||
|
|
||||||
message->FindInt32("device", &device);
|
|
||||||
message->FindInt64("directory", &directory);
|
|
||||||
message->FindString("name", &name);
|
|
||||||
|
|
||||||
entry_ref ref(device, directory, name);
|
|
||||||
|
|
||||||
if ((status = entry.SetTo(&ref)) != B_OK)
|
|
||||||
return status;
|
|
||||||
if ((status = entry.GetPath(&path)) != B_OK)
|
|
||||||
return status;
|
|
||||||
if ((status = path.InitCheck()) != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
if (opcode == B_ENTRY_CREATED)
|
if (opcode == B_ENTRY_CREATED)
|
||||||
_AddDevice(path.Path());
|
return _AddDevice(path);
|
||||||
else
|
|
||||||
_RemoveDevice(path.Path());
|
|
||||||
|
|
||||||
return status;
|
return _RemoveDevice(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -597,9 +561,9 @@ KeyboardInputDevice::_RemoveDevice(const char *path)
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
keyboard_device* device;
|
keyboard_device* device;
|
||||||
for (int i = 0; (device = (keyboard_device *)fDevices.ItemAt(i)) != NULL; i++) {
|
for (int i = 0; (device = fDevices.ItemAt(i)) != NULL; i++) {
|
||||||
if (!strcmp(device->path, path)) {
|
if (!strcmp(device->path, path)) {
|
||||||
fDevices.RemoveItem(device);
|
fDevices.RemoveItemAt(i);
|
||||||
|
|
||||||
input_device_ref* devices[2];
|
input_device_ref* devices[2];
|
||||||
devices[0] = &device->device_ref;
|
devices[0] = &device->device_ref;
|
||||||
@@ -643,17 +607,17 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
|
|||||||
LOG("KB_READ :");
|
LOG("KB_READ :");
|
||||||
|
|
||||||
if (device->isAT) {
|
if (device->isAT) {
|
||||||
at_kbd_io *at_kbd = (at_kbd_io *)buffer;
|
at_kbd_io* atKeyboard = (at_kbd_io*)buffer;
|
||||||
if (at_kbd->scancode > 0)
|
if (atKeyboard->scancode > 0)
|
||||||
keycode = kATKeycodeMap[at_kbd->scancode-1];
|
keycode = kATKeycodeMap[atKeyboard->scancode - 1];
|
||||||
isKeyDown = at_kbd->is_keydown;
|
isKeyDown = atKeyboard->is_keydown;
|
||||||
timestamp = at_kbd->timestamp;
|
timestamp = atKeyboard->timestamp;
|
||||||
LOG(" %02x", at_kbd->scancode);
|
LOG(" %02x", atKeyboard->scancode);
|
||||||
} else {
|
} else {
|
||||||
raw_key_info *raw_kbd = (raw_key_info *)buffer;
|
raw_key_info* rawKeyInfo= (raw_key_info*)buffer;
|
||||||
isKeyDown = raw_kbd->is_keydown;
|
isKeyDown = rawKeyInfo->is_keydown;
|
||||||
timestamp = raw_kbd->timestamp;
|
timestamp = rawKeyInfo->timestamp;
|
||||||
keycode = raw_kbd->be_keycode;
|
keycode = rawKeyInfo->be_keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keycode == 0)
|
if (keycode == 0)
|
||||||
@@ -692,11 +656,11 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
|
|||||||
LOG("TeamMonitor called\n");
|
LOG("TeamMonitor called\n");
|
||||||
|
|
||||||
// show the team monitor
|
// show the team monitor
|
||||||
if (owner->fTMWindow == NULL)
|
if (owner->fTeamMonitorWindow == NULL)
|
||||||
owner->fTMWindow = new (std::nothrow) TMWindow();
|
owner->fTeamMonitorWindow = new (std::nothrow) TMWindow();
|
||||||
|
|
||||||
if (owner->fTMWindow != NULL) {
|
if (owner->fTeamMonitorWindow != NULL) {
|
||||||
owner->fTMWindow->Enable();
|
owner->fTeamMonitorWindow->Enable();
|
||||||
|
|
||||||
// cancel timer only for R5
|
// cancel timer only for R5
|
||||||
if (ioctl(device->fd, KB_CANCEL_CONTROL_ALT_DEL, NULL) == B_OK)
|
if (ioctl(device->fd, KB_CANCEL_CONTROL_ALT_DEL, NULL) == B_OK)
|
||||||
@@ -739,7 +703,8 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
|
|||||||
newDeadKey = keymap->IsDeadKey(keycode, device->modifiers);
|
newDeadKey = keymap->IsDeadKey(keycode, device->modifiers);
|
||||||
|
|
||||||
if (newDeadKey == 0) {
|
if (newDeadKey == 0) {
|
||||||
char *string = NULL, *rawString = NULL;
|
char* string = NULL;
|
||||||
|
char* rawString = NULL;
|
||||||
int32 numBytes = 0, rawNumBytes = 0;
|
int32 numBytes = 0, rawNumBytes = 0;
|
||||||
keymap->GetChars(keycode, device->modifiers, activeDeadKey, &string, &numBytes);
|
keymap->GetChars(keycode, device->modifiers, activeDeadKey, &string, &numBytes);
|
||||||
keymap->GetChars(keycode, 0, 0, &rawString, &rawNumBytes);
|
keymap->GetChars(keycode, 0, 0, &rawString, &rawNumBytes);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006, Jérôme Duval. All rights reserved.
|
* Copyright 2004-2008, Jérôme Duval. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef KEYBOARD_INPUT_DEVICE_H
|
#ifndef KEYBOARD_INPUT_DEVICE_H
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <ObjectList.h>
|
||||||
|
|
||||||
|
|
||||||
class KeyboardInputDevice;
|
class KeyboardInputDevice;
|
||||||
@@ -25,8 +25,10 @@ struct keyboard_device : public BHandler {
|
|||||||
virtual ~keyboard_device();
|
virtual ~keyboard_device();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
status_t EnqueueInlineInputMethod(int32 opcode, const char* string = NULL,
|
status_t EnqueueInlineInputMethod(int32 opcode,
|
||||||
bool confirmed = false, BMessage* keyDown = NULL);
|
const char* string = NULL,
|
||||||
|
bool confirmed = false,
|
||||||
|
BMessage* keyDown = NULL);
|
||||||
|
|
||||||
KeyboardInputDevice* owner;
|
KeyboardInputDevice* owner;
|
||||||
input_device_ref device_ref;
|
input_device_ref device_ref;
|
||||||
@@ -56,10 +58,6 @@ class KeyboardInputDevice : public BInputServerDevice {
|
|||||||
|
|
||||||
virtual status_t SystemShuttingDown();
|
virtual status_t SystemShuttingDown();
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
static FILE *sLogFile;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _HandleMonitor(BMessage* message);
|
status_t _HandleMonitor(BMessage* message);
|
||||||
status_t _InitFromSettings(void* cookie, uint32 opcode = 0);
|
status_t _InitFromSettings(void* cookie, uint32 opcode = 0);
|
||||||
@@ -68,27 +66,16 @@ class KeyboardInputDevice : public BInputServerDevice {
|
|||||||
status_t _AddDevice(const char* path);
|
status_t _AddDevice(const char* path);
|
||||||
status_t _RemoveDevice(const char* path);
|
status_t _RemoveDevice(const char* path);
|
||||||
|
|
||||||
static int32 _DeviceWatcher(void *arg);
|
|
||||||
|
|
||||||
void _SetLeds(keyboard_device* device);
|
void _SetLeds(keyboard_device* device);
|
||||||
|
|
||||||
BList fDevices;
|
static int32 _DeviceWatcher(void* arg);
|
||||||
|
|
||||||
|
BObjectList<keyboard_device> fDevices;
|
||||||
Keymap fKeymap;
|
Keymap fKeymap;
|
||||||
TMWindow *fTMWindow;
|
TMWindow* fTeamMonitorWindow;
|
||||||
BLocker fKeymapLock;
|
BLocker fKeymapLock;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" BInputServerDevice* instantiate_input_device();
|
extern "C" BInputServerDevice* instantiate_input_device();
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
|
|
||||||
fputs(buf, KeyboardInputDevice::sLogFile); fflush(KeyboardInputDevice::sLogFile); }
|
|
||||||
#define LOG_ERR(text...) LOG(text)
|
|
||||||
#else
|
|
||||||
#define LOG(text...)
|
|
||||||
#define LOG_ERR(text...) fprintf(stderr, text)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
|
|
||||||
|
|
||||||
#endif // KEYBOARD_INPUT_DEVICE_H
|
#endif // KEYBOARD_INPUT_DEVICE_H
|
||||||
|
|||||||
@@ -259,7 +259,6 @@ TMView::Pulse()
|
|||||||
void
|
void
|
||||||
TMView::UpdateList()
|
TMView::UpdateList()
|
||||||
{
|
{
|
||||||
CALLED();
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
for (int32 i = 0; i < fListView->CountItems(); i++) {
|
for (int32 i = 0; i < fListView->CountItems(); i++) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src add-ons input_server devices mouse ;
|
|||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
|
|
||||||
UsePrivateHeaders input ;
|
UsePrivateHeaders input shared ;
|
||||||
|
|
||||||
Addon <input>mouse :
|
Addon <input>mouse :
|
||||||
MouseInputDevice.cpp
|
MouseInputDevice.cpp
|
||||||
|
|||||||
@@ -10,8 +10,12 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "MouseInputDevice.h"
|
#include "MouseInputDevice.h"
|
||||||
#include "kb_mouse_settings.h"
|
|
||||||
#include "kb_mouse_driver.h"
|
#include <errno.h>
|
||||||
|
#include <new>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
@@ -21,28 +25,25 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include "kb_mouse_settings.h"
|
||||||
#include <new>
|
#include "kb_mouse_driver.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
FILE *MouseInputDevice::sLogFile = NULL;
|
//#define TRACE_MOUSE_DEVICE
|
||||||
|
#ifdef TRACE_MOUSE_DEVICE
|
||||||
|
# define LOG(text...) debug_printf(text)
|
||||||
# define LOG_ERR(text...) LOG(text)
|
# define LOG_ERR(text...) LOG(text)
|
||||||
#else
|
#else
|
||||||
# define LOG(text...)
|
# define LOG(text...) do {} while (0)
|
||||||
# define LOG_ERR(text...) fprintf(stderr, text)
|
# define LOG_ERR(text...) debug_printf(text)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
|
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
|
|
||||||
const static uint32 kMouseThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
|
const static uint32 kMouseThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
|
||||||
const static char* kMouseDevicesDirectory = "/dev/input/mouse";
|
const static char* kMouseDevicesDirectory = "/dev/input/mouse";
|
||||||
|
|
||||||
// "/dev/" is automatically prepended by StartMonitoringDevice()
|
|
||||||
const static char *kMouseDevicesDirectoryPS2 = "input/mouse/ps2";
|
|
||||||
const static char *kMouseDevicesDirectoryUSB = "input/mouse/usb";
|
|
||||||
|
|
||||||
class MouseDevice {
|
class MouseDevice {
|
||||||
public:
|
public:
|
||||||
@@ -83,19 +84,6 @@ class MouseDevice {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
inline void
|
|
||||||
LOG(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
char buf[1024];
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vsprintf(buf, fmt, ap); va_end(ap);
|
|
||||||
fputs(buf, MouseInputDevice::sLogFile); fflush(MouseInputDevice::sLogFile);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" BInputServerDevice*
|
extern "C" BInputServerDevice*
|
||||||
instantiate_input_device()
|
instantiate_input_device()
|
||||||
{
|
{
|
||||||
@@ -412,15 +400,12 @@ MouseDevice::_BuildShortName() const
|
|||||||
|
|
||||||
|
|
||||||
MouseInputDevice::MouseInputDevice()
|
MouseInputDevice::MouseInputDevice()
|
||||||
|
:
|
||||||
|
fDevices(2, true)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
|
||||||
sLogFile = fopen("/var/log/mouse_device_log.log", "a");
|
|
||||||
#endif
|
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
StartMonitoringDevice(kMouseDevicesDirectoryPS2);
|
StartMonitoringDevice(kMouseDevicesDirectory);
|
||||||
StartMonitoringDevice(kMouseDevicesDirectoryUSB);
|
|
||||||
|
|
||||||
_RecursiveScan(kMouseDevicesDirectory);
|
_RecursiveScan(kMouseDevicesDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,17 +413,7 @@ MouseInputDevice::MouseInputDevice()
|
|||||||
MouseInputDevice::~MouseInputDevice()
|
MouseInputDevice::~MouseInputDevice()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
StopMonitoringDevice(kMouseDevicesDirectoryUSB);
|
StopMonitoringDevice(kMouseDevicesDirectory);
|
||||||
StopMonitoringDevice(kMouseDevicesDirectoryPS2);
|
|
||||||
|
|
||||||
int32 count = fDevices.CountItems();
|
|
||||||
while (count-- > 0) {
|
|
||||||
delete (MouseDevice *)fDevices.RemoveItem(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
fclose(sLogFile);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -495,40 +470,17 @@ MouseInputDevice::_HandleMonitor(BMessage* message)
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
|
const char* path;
|
||||||
int32 opcode;
|
int32 opcode;
|
||||||
if (message->FindInt32("opcode", &opcode) < B_OK)
|
if (message->FindInt32("opcode", &opcode) != B_OK
|
||||||
|
|| opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED
|
||||||
|
|| message->FindString("path", &path) != B_OK)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
if (opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED)
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
BEntry entry;
|
|
||||||
BPath path;
|
|
||||||
dev_t device;
|
|
||||||
ino_t directory;
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
if (message->FindInt32("device", &device) < B_OK
|
|
||||||
|| message->FindInt64("directory", &directory) < B_OK
|
|
||||||
|| message->FindString("name", &name) < B_OK)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
entry_ref ref(device, directory, name);
|
|
||||||
status_t status;
|
|
||||||
|
|
||||||
if ((status = entry.SetTo(&ref)) != B_OK)
|
|
||||||
return status;
|
|
||||||
if ((status = entry.GetPath(&path)) != B_OK)
|
|
||||||
return status;
|
|
||||||
if ((status = path.InitCheck()) != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
if (opcode == B_ENTRY_CREATED)
|
if (opcode == B_ENTRY_CREATED)
|
||||||
status = _AddDevice(path.Path());
|
return _AddDevice(path);
|
||||||
else
|
|
||||||
status = _RemoveDevice(path.Path());
|
|
||||||
|
|
||||||
return status;
|
return _RemoveDevice(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -538,7 +490,7 @@ MouseInputDevice::_FindDevice(const char *path)
|
|||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
for (int32 i = fDevices.CountItems(); i-- > 0;) {
|
for (int32 i = fDevices.CountItems(); i-- > 0;) {
|
||||||
MouseDevice* device = (MouseDevice*)fDevices.ItemAt(i);
|
MouseDevice* device = fDevices.ItemAt(i);
|
||||||
if (!strcmp(device->Path(), path))
|
if (!strcmp(device->Path(), path))
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2006, Haiku.
|
* Copyright 2004-2008, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -11,9 +11,8 @@
|
|||||||
|
|
||||||
#include <InputServerDevice.h>
|
#include <InputServerDevice.h>
|
||||||
#include <InterfaceDefs.h>
|
#include <InterfaceDefs.h>
|
||||||
#include <List.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <ObjectList.h>
|
||||||
|
|
||||||
|
|
||||||
class MouseDevice;
|
class MouseDevice;
|
||||||
@@ -39,11 +38,7 @@ class MouseInputDevice : public BInputServerDevice {
|
|||||||
status_t _AddDevice(const char* path);
|
status_t _AddDevice(const char* path);
|
||||||
status_t _RemoveDevice(const char* path);
|
status_t _RemoveDevice(const char* path);
|
||||||
|
|
||||||
BList fDevices;
|
BObjectList<MouseDevice> fDevices;
|
||||||
#ifdef DEBUG
|
|
||||||
public:
|
|
||||||
static FILE *sLogFile;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" BInputServerDevice* instantiate_input_device();
|
extern "C" BInputServerDevice* instantiate_input_device();
|
||||||
|
|||||||
Reference in New Issue
Block a user