* 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:
Axel Dörfler
2008-10-19 15:59:23 +00:00
parent 23debb05d0
commit b6a7b20419
7 changed files with 233 additions and 335 deletions
@@ -2,10 +2,10 @@ SubDir HAIKU_TOP src add-ons input_server devices keyboard ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders input interface tracker ;
UsePrivateHeaders input interface shared tracker ;
UsePrivateSystemHeaders ;
Addon <input>keyboard :
Addon <input>keyboard :
KeyboardInputDevice.cpp
Keymap.cpp
@@ -15,5 +15,5 @@ Addon <input>keyboard :
: input_server be ;
Package haiku-inputkit-cvs :
<input>keyboard :
<input>keyboard :
boot home config add-ons input_server devices ;
@@ -1,11 +1,18 @@
/*
* 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.
*/
#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 <Autolock.h>
@@ -15,22 +22,23 @@
#include <Path.h>
#include <String.h>
#include <errno.h>
#include <new>
#include <stdlib.h>
#include <unistd.h>
#include "kb_mouse_driver.h"
#if DEBUG
FILE *KeyboardInputDevice::sLogFile = NULL;
//#define TRACE_KEYBOARD_DEVICE
#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
const static uint32 kKeyboardThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
const static char *kKeyboardDevicesDirectory = "/dev/input/keyboard";
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
// "/dev/" is automatically prepended by StartMonitoringDevice()
const static char *kKeyboardDevicesDirectoryPS2 = "input/keyboard/at";
const static char *kKeyboardDevicesDirectoryUSB = "input/keyboard/usb";
const static uint32 kKeyboardThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
const static char* kKeyboardDevicesDirectory = "/dev/input/keyboard";
const static uint32 kATKeycodeMap[] = {
0x1, // Esc
@@ -57,7 +65,7 @@ const static uint32 kATKeycodeMap[] = {
0x2d, // U
0x2e, // I
0x2f, // O
0x30, // P
0x30, // P
0x31, // [
0x32, // ]
0x47, // ENTER
@@ -327,16 +335,15 @@ const static uint32 kATKeycodeMap[] = {
};
extern "C"
BInputServerDevice *
extern "C" BInputServerDevice*
instantiate_input_device()
{
return new (std::nothrow) KeyboardInputDevice();
return new(std::nothrow) KeyboardInputDevice();
}
static char *
get_short_name(const char *longName)
static char*
get_short_name(const char* longName)
{
CALLED();
BString string(longName);
@@ -366,57 +373,47 @@ get_short_name(const char *longName)
KeyboardInputDevice::KeyboardInputDevice()
:
fTMWindow(NULL),
fDevices(2, true),
fTeamMonitorWindow(NULL),
fKeymapLock("keymap lock")
{
#if DEBUG
if (sLogFile == NULL)
sLogFile = fopen("/var/log/keyboard_device_log.log", "a");
#endif
CALLED();
StartMonitoringDevice(kKeyboardDevicesDirectory);
_RecursiveScan(kKeyboardDevicesDirectory);
}
KeyboardInputDevice::~KeyboardInputDevice()
{
CALLED();
StopMonitoringDevice(kKeyboardDevicesDirectoryUSB);
StopMonitoringDevice(kKeyboardDevicesDirectoryPS2);
int count = fDevices.CountItems();
while (count-- > 0) {
delete (keyboard_device *)fDevices.RemoveItem((int32)0);
}
#if DEBUG
fclose(sLogFile);
#endif
StopMonitoringDevice(kKeyboardDevicesDirectory);
}
status_t
status_t
KeyboardInputDevice::SystemShuttingDown()
{
CALLED();
if (fTMWindow)
fTMWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
if (fTeamMonitorWindow)
fTeamMonitorWindow->PostMessage(SYSTEM_SHUTTING_DOWN);
return B_OK;
}
status_t
KeyboardInputDevice::_InitFromSettings(void *cookie, uint32 opcode)
KeyboardInputDevice::_InitFromSettings(void* cookie, uint32 opcode)
{
CALLED();
keyboard_device *device = (keyboard_device *)cookie;
keyboard_device* device = (keyboard_device*)cookie;
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, KB_SET_KEY_REPEAT_RATE,
&device->settings.key_repeat_rate) != B_OK)
&device->settings.key_repeat_rate) != B_OK)
LOG_ERR("error when KB_SET_KEY_REPEAT_RATE, fd:%d\n", device->fd);
}
@@ -424,12 +421,11 @@ KeyboardInputDevice::_InitFromSettings(void *cookie, uint32 opcode)
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, 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);
}
if (opcode == 0
|| opcode == B_KEY_MAP_CHANGED
if (opcode == 0 || opcode == B_KEY_MAP_CHANGED
|| opcode == B_KEY_LOCKS_CHANGED) {
BAutolock lock(fKeymapLock);
fKeymap.LoadCurrent();
@@ -445,25 +441,15 @@ status_t
KeyboardInputDevice::InitCheck()
{
CALLED();
status_t status = BInputServerDevice::InitCheck();
if (status < B_OK)
return status;
// TODO: this doesn't belong here!
_RecursiveScan(kKeyboardDevicesDirectory);
StartMonitoringDevice(kKeyboardDevicesDirectoryPS2);
StartMonitoringDevice(kKeyboardDevicesDirectoryUSB);
return B_OK;
return BInputServerDevice::InitCheck();
}
status_t
KeyboardInputDevice::Start(const char *name, void *cookie)
KeyboardInputDevice::Start(const char* name, void* cookie)
{
CALLED();
keyboard_device *device = (keyboard_device *)cookie;
keyboard_device* device = (keyboard_device*)cookie;
if ((device->fd = open(device->path, O_RDWR)) < B_OK) {
fprintf(stderr, "error when opening %s: %s\n", device->path, strerror(errno));
@@ -487,10 +473,10 @@ KeyboardInputDevice::Start(const char *name, void *cookie)
status_t
KeyboardInputDevice::Stop(const char *name, void *cookie)
KeyboardInputDevice::Stop(const char* name, void* cookie)
{
CALLED();
keyboard_device *device = (keyboard_device *)cookie;
keyboard_device* device = (keyboard_device*)cookie;
LOG("Stop(%s)\n", name);
@@ -505,9 +491,9 @@ KeyboardInputDevice::Stop(const char *name, void *cookie)
wait_for_thread(device->device_watcher, &dummy);
}
if (fTMWindow) {
fTMWindow->PostMessage(B_QUIT_REQUESTED);
fTMWindow = NULL;
if (fTeamMonitorWindow) {
fTeamMonitorWindow->PostMessage(B_QUIT_REQUESTED);
fTeamMonitorWindow = NULL;
}
return B_OK;
@@ -515,15 +501,15 @@ KeyboardInputDevice::Stop(const char *name, void *cookie)
status_t
KeyboardInputDevice::Control(const char *name, void *cookie,
uint32 command, BMessage *message)
KeyboardInputDevice::Control(const char* name, void* cookie,
uint32 command, BMessage* message)
{
CALLED();
LOG("Control(%s, code: %lu)\n", name, command);
if (command == B_NODE_MONITOR)
_HandleMonitor(message);
else if (command >= B_KEY_MAP_CHANGED
else if (command >= B_KEY_MAP_CHANGED
&& command <= B_KEY_REPEAT_RATE_CHANGED) {
_InitFromSettings(cookie, command);
}
@@ -532,57 +518,35 @@ KeyboardInputDevice::Control(const char *name, void *cookie,
status_t
KeyboardInputDevice::_HandleMonitor(BMessage *message)
KeyboardInputDevice::_HandleMonitor(BMessage* message)
{
CALLED();
int32 opcode = 0;
status_t status;
if ((status = message->FindInt32("opcode", &opcode)) < B_OK)
return status;
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 = 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;
const char* path;
int32 opcode;
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;
if (opcode == B_ENTRY_CREATED)
_AddDevice(path.Path());
else
_RemoveDevice(path.Path());
return _AddDevice(path);
return status;
return _RemoveDevice(path);
}
status_t
KeyboardInputDevice::_AddDevice(const char *path)
KeyboardInputDevice::_AddDevice(const char* path)
{
CALLED();
keyboard_device *device = new (std::nothrow) keyboard_device(path);
keyboard_device* device = new(std::nothrow) keyboard_device(path);
if (device == NULL)
return B_NO_MEMORY;
device->owner = this;
input_device_ref *devices[2];
input_device_ref* devices[2];
devices[0] = &device->device_ref;
devices[1] = NULL;
@@ -593,22 +557,22 @@ KeyboardInputDevice::_AddDevice(const char *path)
status_t
KeyboardInputDevice::_RemoveDevice(const char *path)
KeyboardInputDevice::_RemoveDevice(const char* path)
{
CALLED();
keyboard_device *device;
for (int i = 0; (device = (keyboard_device *)fDevices.ItemAt(i)) != NULL; i++) {
keyboard_device* device;
for (int i = 0; (device = fDevices.ItemAt(i)) != NULL; i++) {
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[1] = NULL;
UnregisterDevices(devices);
delete device;
return B_OK;
}
}
}
return B_ENTRY_NOT_FOUND;
@@ -616,10 +580,10 @@ KeyboardInputDevice::_RemoveDevice(const char *path)
/*static*/ int32
KeyboardInputDevice::_DeviceWatcher(void *arg)
KeyboardInputDevice::_DeviceWatcher(void* arg)
{
CALLED();
keyboard_device* device = (keyboard_device *)arg;
keyboard_device* device = (keyboard_device*)arg;
KeyboardInputDevice* owner = device->owner;
uint8 buffer[16];
uint8 activeDeadKey = 0;
@@ -643,17 +607,17 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
LOG("KB_READ :");
if (device->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);
at_kbd_io* atKeyboard = (at_kbd_io*)buffer;
if (atKeyboard->scancode > 0)
keycode = kATKeycodeMap[atKeyboard->scancode - 1];
isKeyDown = atKeyboard->is_keydown;
timestamp = atKeyboard->timestamp;
LOG(" %02x", atKeyboard->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;
raw_key_info* rawKeyInfo= (raw_key_info*)buffer;
isKeyDown = rawKeyInfo->is_keydown;
timestamp = rawKeyInfo->timestamp;
keycode = rawKeyInfo->be_keycode;
}
if (keycode == 0)
@@ -671,7 +635,7 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
}
}
if (noOtherKeyPressed) {
if (noOtherKeyPressed) {
BMessenger deskbar("application/x-vnd.Be-TSKB");
if (deskbar.IsValid())
deskbar.SendMessage('BeMn');
@@ -692,11 +656,11 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
LOG("TeamMonitor called\n");
// show the team monitor
if (owner->fTMWindow == NULL)
owner->fTMWindow = new (std::nothrow) TMWindow();
if (owner->fTeamMonitorWindow == NULL)
owner->fTeamMonitorWindow = new (std::nothrow) TMWindow();
if (owner->fTMWindow != NULL) {
owner->fTMWindow->Enable();
if (owner->fTeamMonitorWindow != NULL) {
owner->fTeamMonitorWindow->Enable();
// cancel timer only for R5
if (ioctl(device->fd, KB_CANCEL_CONTROL_ALT_DEL, NULL) == B_OK)
@@ -707,10 +671,10 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
BAutolock lock(owner->fKeymapLock);
uint32 modifiers = keymap->Modifier(keycode);
if (modifiers
&& (!(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK))
if (modifiers
&& (!(modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK))
|| isKeyDown)) {
BMessage *msg = new BMessage;
BMessage* msg = new BMessage;
if (msg == NULL)
continue;
@@ -739,12 +703,13 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
newDeadKey = keymap->IsDeadKey(keycode, device->modifiers);
if (newDeadKey == 0) {
char *string = NULL, *rawString = NULL;
char* string = NULL;
char* rawString = NULL;
int32 numBytes = 0, rawNumBytes = 0;
keymap->GetChars(keycode, device->modifiers, activeDeadKey, &string, &numBytes);
keymap->GetChars(keycode, 0, 0, &rawString, &rawNumBytes);
BMessage *msg = new BMessage;
BMessage* msg = new BMessage;
if (msg == NULL) {
free(string);
free(rawString);
@@ -796,7 +761,7 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
} else if (isKeyDown) {
// start of a dead key
if (device->EnqueueInlineInputMethod(B_INPUT_METHOD_STARTED) == B_OK) {
char *string = NULL;
char* string = NULL;
int32 numBytes = 0;
keymap->GetChars(keycode, device->modifiers, 0, &string, &numBytes);
@@ -822,7 +787,7 @@ KeyboardInputDevice::_DeviceWatcher(void *arg)
void
KeyboardInputDevice::_RecursiveScan(const char *directory)
KeyboardInputDevice::_RecursiveScan(const char* directory)
{
CALLED();
BEntry entry;
@@ -839,7 +804,7 @@ KeyboardInputDevice::_RecursiveScan(const char *directory)
void
KeyboardInputDevice::_SetLeds(keyboard_device *device)
KeyboardInputDevice::_SetLeds(keyboard_device* device)
{
if (device->fd < 0)
return;
@@ -861,7 +826,7 @@ KeyboardInputDevice::_SetLeds(keyboard_device *device)
// #pragma mark -
keyboard_device::keyboard_device(const char *path)
keyboard_device::keyboard_device(const char* path)
: BHandler("keyboard device"),
owner(NULL),
fd(-1),
@@ -923,7 +888,7 @@ keyboard_device::EnqueueInlineInputMethod(int32 opcode,
void
keyboard_device::MessageReceived(BMessage *message)
keyboard_device::MessageReceived(BMessage* message)
{
if (message->what != B_INPUT_METHOD_EVENT) {
BHandler::MessageReceived(message);
@@ -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.
*/
#ifndef KEYBOARD_INPUT_DEVICE_H
@@ -15,80 +15,67 @@
#include <Locker.h>
#include <List.h>
#include <stdio.h>
#include <ObjectList.h>
class KeyboardInputDevice;
struct keyboard_device : public BHandler {
keyboard_device(const char *path);
virtual ~keyboard_device();
keyboard_device(const char* path);
virtual ~keyboard_device();
virtual void MessageReceived(BMessage* message);
status_t EnqueueInlineInputMethod(int32 opcode, const char* string = NULL,
bool confirmed = false, BMessage* keyDown = NULL);
virtual void MessageReceived(BMessage* message);
status_t EnqueueInlineInputMethod(int32 opcode,
const char* string = NULL,
bool confirmed = false,
BMessage* keyDown = NULL);
KeyboardInputDevice *owner;
input_device_ref device_ref;
char path[B_PATH_NAME_LENGTH];
int fd;
thread_id device_watcher;
kb_settings settings;
volatile bool active;
bool isAT;
volatile bool input_method_started;
uint32 modifiers;
KeyboardInputDevice* owner;
input_device_ref device_ref;
char path[B_PATH_NAME_LENGTH];
int fd;
thread_id device_watcher;
kb_settings settings;
volatile bool active;
bool isAT;
volatile bool input_method_started;
uint32 modifiers;
};
class KeyboardInputDevice : public BInputServerDevice {
public:
KeyboardInputDevice();
~KeyboardInputDevice();
public:
KeyboardInputDevice();
~KeyboardInputDevice();
virtual status_t InitCheck();
virtual status_t InitCheck();
virtual status_t Start(const char *name, void *cookie);
virtual status_t Stop(const char *name, void *cookie);
virtual status_t Start(const char* name, void* cookie);
virtual status_t Stop(const char* name, void* cookie);
virtual status_t Control(const char *name, void *cookie,
uint32 command, BMessage *message);
virtual status_t Control(const char* name, void* cookie,
uint32 command, BMessage* message);
virtual status_t SystemShuttingDown();
virtual status_t SystemShuttingDown();
#ifdef DEBUG
static FILE *sLogFile;
#endif
private:
status_t _HandleMonitor(BMessage* message);
status_t _InitFromSettings(void* cookie, uint32 opcode = 0);
void _RecursiveScan(const char* directory);
private:
status_t _HandleMonitor(BMessage *message);
status_t _InitFromSettings(void *cookie, uint32 opcode = 0);
void _RecursiveScan(const char *directory);
status_t _AddDevice(const char* path);
status_t _RemoveDevice(const char* path);
status_t _AddDevice(const char *path);
status_t _RemoveDevice(const char *path);
void _SetLeds(keyboard_device* device);
static int32 _DeviceWatcher(void *arg);
static int32 _DeviceWatcher(void* arg);
void _SetLeds(keyboard_device *device);
BList fDevices;
Keymap fKeymap;
TMWindow *fTMWindow;
BLocker fKeymapLock;
BObjectList<keyboard_device> fDevices;
Keymap fKeymap;
TMWindow* fTeamMonitorWindow;
BLocker fKeymapLock;
};
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__)
extern "C" BInputServerDevice* instantiate_input_device();
#endif // KEYBOARD_INPUT_DEVICE_H
@@ -2,7 +2,7 @@
//
// Copyright (c) 2004-2005, Haiku
//
// This software is part of the Haiku distribution and is covered
// This software is part of the Haiku distribution and is covered
// by the MIT license.
//
//
@@ -10,7 +10,7 @@
// Author: Jérôme Duval
// Description: Keyboard input server addon
// Created : October 13, 2004
//
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
@@ -42,8 +42,8 @@ extern "C" void _kshutdown_(bool reboot);
TMWindow::TMWindow()
: BWindow(BRect(0, 0, 350, 300), "Team Monitor",
B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL,
: BWindow(BRect(0, 0, 350, 300), "Team Monitor",
B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL,
B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS,
B_ALL_WORKSPACES),
fQuitting(false)
@@ -51,20 +51,20 @@ TMWindow::TMWindow()
if (Lock()) {
// ToDo: make this font sensitive
fView = new TMView(Bounds(), "background", B_FOLLOW_ALL,
B_WILL_DRAW, B_NO_BORDER);
AddChild(fView);
float width, height;
fView->GetPreferredSize(&width, &height);
ResizeTo(width, height);
BRect screenFrame = BScreen(this).Frame();
BPoint point;
point.x = (screenFrame.Width() - Bounds().Width()) / 2;
point.y = (screenFrame.Height() - Bounds().Height()) / 2;
if (screenFrame.Contains(point))
MoveTo(point);
SetSizeLimits(Bounds().Width(), Bounds().Width()*2, Bounds().Height(), Bounds().Height()*2);
@@ -105,7 +105,7 @@ TMWindow::Enable()
{
if (Lock()) {
SetPulseRate(1000000);
if (IsHidden()) {
fView->UpdateList();
Show();
@@ -138,14 +138,14 @@ TMView::TMView(BRect bounds, const char* name, uint32 resizeFlags,
rect.bottom -= 14;
rect.top = rect.bottom - 20;
BButton *cancel = new BButton(rect, "cancel", "Cancel",
BButton *cancel = new BButton(rect, "cancel", "Cancel",
new BMessage(TM_CANCEL), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
AddChild(cancel);
rect.left = 10;
rect.right = rect.left + font.StringWidth("Force Reboot") + 20;
BButton *forceReboot = new BButton(rect, "force", "Force Reboot",
BButton *forceReboot = new BButton(rect, "force", "Force Reboot",
new BMessage(TM_FORCE_REBOOT), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
AddChild(forceReboot);
@@ -164,7 +164,7 @@ TMView::TMView(BRect bounds, const char* name, uint32 resizeFlags,
fDescView = new TMDescView(rect, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
AddChild(fDescView);
fDescView->ResizeToPreferred();
rect = fDescView->Frame();
rect.left = 10;
rect.right = rect.left + font.StringWidth("Kill Application") + 20;
@@ -181,15 +181,15 @@ TMView::TMView(BRect bounds, const char* name, uint32 resizeFlags,
rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom = fKillButton->Frame().top - 10;
fListView = new BListView(rect, "teams", B_SINGLE_SELECTION_LIST,
fListView = new BListView(rect, "teams", B_SINGLE_SELECTION_LIST,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM);
fListView->SetSelectionMessage(new BMessage(TM_SELECTED_TEAM));
BScrollView *scrollView = new BScrollView("scroll_teams", fListView,
BScrollView *scrollView = new BScrollView("scroll_teams", fListView,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP_BOTTOM, 0, false, true, B_FANCY_BORDER);
AddChild(scrollView);
}
@@ -259,7 +259,6 @@ TMView::Pulse()
void
TMView::UpdateList()
{
CALLED();
bool changed = false;
for (int32 i = 0; i < fListView->CountItems(); i++) {
@@ -289,7 +288,7 @@ TMView::UpdateList()
item->fFound = true;
changed = true;
}
}
}
for (int32 i = fListView->CountItems() - 1; i >= 0; i--) {
TMListItem *item = (TMListItem*)fListView->ItemAt(i);
@@ -2,10 +2,10 @@ SubDir HAIKU_TOP src add-ons input_server devices mouse ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders input ;
UsePrivateHeaders input shared ;
Addon <input>mouse :
MouseInputDevice.cpp
Addon <input>mouse :
MouseInputDevice.cpp
: be input_server ;
Package haiku-inputkit-cvs :
@@ -10,8 +10,12 @@
#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 <Directory.h>
@@ -21,28 +25,25 @@
#include <String.h>
#include <View.h>
#include <errno.h>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "kb_mouse_settings.h"
#include "kb_mouse_driver.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)
#else
# define LOG(text...)
# define LOG_ERR(text...) fprintf(stderr, text)
# define LOG(text...) do {} while (0)
# define LOG_ERR(text...) debug_printf(text)
#endif
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
const static uint32 kMouseThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
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";
const static uint32 kMouseThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4;
const static char* kMouseDevicesDirectory = "/dev/input/mouse";
class MouseDevice {
public:
@@ -59,7 +60,7 @@ class MouseDevice {
private:
void _Run();
static status_t _ThreadFunction(void *arg);
static status_t _ThreadFunction(void* arg);
BMessage* _BuildMouseMessage(uint32 what, uint64 when, uint32 buttons,
int32 deltaX, int32 deltaY) const;
@@ -83,30 +84,17 @@ 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()
{
return new (std::nothrow) MouseInputDevice();
return new(std::nothrow) MouseInputDevice();
}
// #pragma mark -
MouseDevice::MouseDevice(BInputServerDevice& target, const char *driverPath)
MouseDevice::MouseDevice(BInputServerDevice& target, const char* driverPath)
:
fTarget(target),
fDevice(-1),
@@ -136,7 +124,7 @@ MouseDevice::~MouseDevice()
free(fDeviceRef.name);
}
status_t
MouseDevice::Start()
@@ -149,9 +137,9 @@ MouseDevice::Start()
char threadName[B_OS_NAME_LENGTH];
snprintf(threadName, B_OS_NAME_LENGTH, "%s watcher", fDeviceRef.name);
fThread = spawn_thread(_ThreadFunction, threadName,
kMouseThreadPriority, (void *)this);
kMouseThreadPriority, (void*)this);
status_t status;
if (fThread < B_OK)
@@ -256,7 +244,7 @@ MouseDevice::_Run()
movements.clicks, movements.wheel_xdelta, movements.wheel_ydelta);
LOG("%s: x: %ld, y: %ld\n", fDeviceRef.name, deltaX, deltaY);
BMessage *message = NULL;
BMessage* message = NULL;
// Send single messages for each event
@@ -268,7 +256,7 @@ MouseDevice::_Run()
if (message != NULL) {
if (pressedButton) {
message->AddInt32("clicks", movements.clicks);
LOG("B_MOUSE_DOWN\n");
LOG("B_MOUSE_DOWN\n");
} else
LOG("B_MOUSE_UP\n");
@@ -303,7 +291,7 @@ MouseDevice::_Run()
status_t
MouseDevice::_ThreadFunction(void* arg)
{
MouseDevice* device = (MouseDevice *)arg;
MouseDevice* device = (MouseDevice*)arg;
device->_Run();
return B_OK;
}
@@ -384,7 +372,7 @@ MouseDevice::_RemapButtons(uint32 buttons) const
}
char *
char*
MouseDevice::_BuildShortName() const
{
BString string(fPath);
@@ -412,15 +400,12 @@ MouseDevice::_BuildShortName() const
MouseInputDevice::MouseInputDevice()
{
#if DEBUG
sLogFile = fopen("/var/log/mouse_device_log.log", "a");
#endif
:
fDevices(2, true)
{
CALLED();
StartMonitoringDevice(kMouseDevicesDirectoryPS2);
StartMonitoringDevice(kMouseDevicesDirectoryUSB);
StartMonitoringDevice(kMouseDevicesDirectory);
_RecursiveScan(kMouseDevicesDirectory);
}
@@ -428,17 +413,7 @@ MouseInputDevice::MouseInputDevice()
MouseInputDevice::~MouseInputDevice()
{
CALLED();
StopMonitoringDevice(kMouseDevicesDirectoryUSB);
StopMonitoringDevice(kMouseDevicesDirectoryPS2);
int32 count = fDevices.CountItems();
while (count-- > 0) {
delete (MouseDevice *)fDevices.RemoveItem(count);
}
#if DEBUG
fclose(sLogFile);
#endif
StopMonitoringDevice(kMouseDevicesDirectory);
}
@@ -451,7 +426,7 @@ MouseInputDevice::InitCheck()
status_t
MouseInputDevice::Start(const char *name, void *cookie)
MouseInputDevice::Start(const char* name, void* cookie)
{
LOG("%s(%s)\n", __PRETTY_FUNCTION__, name);
MouseDevice* device = (MouseDevice*)cookie;
@@ -461,7 +436,7 @@ MouseInputDevice::Start(const char *name, void *cookie)
status_t
MouseInputDevice::Stop(const char *name, void *cookie)
MouseInputDevice::Stop(const char* name, void* cookie)
{
LOG("%s(%s)\n", __PRETTY_FUNCTION__, name);
MouseDevice* device = (MouseDevice*)cookie;
@@ -477,11 +452,11 @@ MouseInputDevice::Control(const char* name, void* cookie,
{
LOG("%s(%s, code: %lu)\n", __PRETTY_FUNCTION__, name, command);
MouseDevice* device = (MouseDevice*)cookie;
if (command == B_NODE_MONITOR)
return _HandleMonitor(message);
if (command >= B_MOUSE_TYPE_CHANGED
if (command >= B_MOUSE_TYPE_CHANGED
&& command <= B_MOUSE_ACCELERATION_CHANGED)
return device->UpdateSettings();
@@ -490,56 +465,33 @@ MouseInputDevice::Control(const char* name, void* cookie,
// TODO: Test this. USB doesn't work on my machine
status_t
status_t
MouseInputDevice::_HandleMonitor(BMessage* message)
{
CALLED();
const char* path;
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;
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)
status = _AddDevice(path.Path());
else
status = _RemoveDevice(path.Path());
return _AddDevice(path);
return status;
return _RemoveDevice(path);
}
MouseDevice*
MouseInputDevice::_FindDevice(const char *path)
MouseInputDevice::_FindDevice(const char* path)
{
CALLED();
for (int32 i = fDevices.CountItems(); i-- > 0;) {
MouseDevice* device = (MouseDevice*)fDevices.ItemAt(i);
if (!strcmp(device->Path(), path))
MouseDevice* device = fDevices.ItemAt(i);
if (!strcmp(device->Path(), path))
return device;
}
@@ -548,11 +500,11 @@ MouseInputDevice::_FindDevice(const char *path)
status_t
MouseInputDevice::_AddDevice(const char *path)
MouseInputDevice::_AddDevice(const char* path)
{
CALLED();
MouseDevice* device = new (std::nothrow) MouseDevice(*this, path);
MouseDevice* device = new(std::nothrow) MouseDevice(*this, path);
if (!device) {
LOG("No memory\n");
return B_NO_MEMORY;
@@ -563,7 +515,7 @@ MouseInputDevice::_AddDevice(const char *path)
return B_NO_MEMORY;
}
input_device_ref *devices[2];
input_device_ref* devices[2];
devices[0] = device->DeviceRef();
devices[1] = NULL;
@@ -572,7 +524,7 @@ MouseInputDevice::_AddDevice(const char *path)
status_t
MouseInputDevice::_RemoveDevice(const char *path)
MouseInputDevice::_RemoveDevice(const char* path)
{
CALLED();
@@ -582,7 +534,7 @@ MouseInputDevice::_RemoveDevice(const char *path)
fDevices.RemoveItem(device);
input_device_ref *devices[2];
input_device_ref* devices[2];
devices[0] = device->DeviceRef();
devices[1] = NULL;
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2006, Haiku.
* Copyright 2004-2008, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -11,39 +11,34 @@
#include <InputServerDevice.h>
#include <InterfaceDefs.h>
#include <List.h>
#include <stdio.h>
#include <ObjectList.h>
class MouseDevice;
class MouseInputDevice : public BInputServerDevice {
public:
MouseInputDevice();
virtual ~MouseInputDevice();
virtual status_t InitCheck();
virtual status_t Start(const char* name, void* cookie);
virtual status_t Stop(const char* name, void* cookie);
virtual status_t Control(const char* name, void* cookie,
uint32 command, BMessage* message);
private:
status_t _HandleMonitor(BMessage* message);
void _RecursiveScan(const char* directory);
MouseDevice* _FindDevice(const char* path);
status_t _AddDevice(const char* path);
status_t _RemoveDevice(const char* path);
BList fDevices;
#ifdef DEBUG
public:
static FILE *sLogFile;
#endif
MouseInputDevice();
virtual ~MouseInputDevice();
virtual status_t InitCheck();
virtual status_t Start(const char* name, void* cookie);
virtual status_t Stop(const char* name, void* cookie);
virtual status_t Control(const char* name, void* cookie,
uint32 command, BMessage* message);
private:
status_t _HandleMonitor(BMessage* message);
void _RecursiveScan(const char* directory);
MouseDevice* _FindDevice(const char* path);
status_t _AddDevice(const char* path);
status_t _RemoveDevice(const char* path);
BObjectList<MouseDevice> fDevices;
};
extern "C" BInputServerDevice* instantiate_input_device();