From 3aa69c787fc9dd5fcf1a08e3e05f89fe616a53ec Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 2 Sep 2004 08:52:54 +0000 Subject: [PATCH] Some changes to the Mouse Input Server Device add-on. B_MOUSE_UP/DOWN still don't work correctly git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8794 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../devices/mouse/MouseInputDevice.cpp | 93 +++++++++++++++---- .../devices/mouse/MouseInputDevice.h | 11 ++- 2 files changed, 82 insertions(+), 22 deletions(-) diff --git a/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp b/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp index c17394f782..7b562c7078 100644 --- a/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp +++ b/src/add-ons/input_server/devices/mouse/MouseInputDevice.cpp @@ -29,6 +29,18 @@ #include #include +//#define DEBUG 1 +#if DEBUG + #define LOG(text) fputs(text, sLogFile) +#else + #define LOG(text) +#endif + +FILE *MouseInputDevice::sLogFile = NULL; + +// TODO: These are "stolen" from the kb_mouse driver on bebits, which uses +// the same protocol as BeOS one. They're just here to test this add-on with +// the BeOS mouse driver. const static uint32 kGetMouseMovements = 10099; const static uint32 kGetMouseAccel = 10101; const static uint32 kSetMouseAccel = 10102; @@ -59,12 +71,15 @@ MouseInputDevice::MouseInputDevice() : fThread(-1), fQuit(false) { + // TODO: Open "/dev/input/mouse/serial/0" as well, and what about USB mouses ? fFd = open("dev/input/mouse/ps2/0", O_RDWR); if (fFd >= 0) fThread = spawn_thread(DeviceWatcher, "mouse watcher thread", B_NORMAL_PRIORITY, this); - - fLogFile = fopen("/boot/home/device_log.log", "w"); + +#if DEBUG + sLogFile = fopen("/var/log/mouse_device_log.log", "w"); +#endif } @@ -77,8 +92,10 @@ MouseInputDevice::~MouseInputDevice() if (fFd >= 0) close(fFd); - - fclose(fLogFile); + +#if DEBUG + fclose(sLogFile); +#endif } @@ -140,9 +157,10 @@ MouseInputDevice::InitCheck() status_t MouseInputDevice::Start(const char *name, void *cookie) { - fputs("Start(", fLogFile); - fputs(name, fLogFile); - fputs(")\n", fLogFile); + char log[128]; + snprintf(log, 128, "Start(%s)\n", name); + + LOG(log); resume_thread(fThread); return B_OK; @@ -150,9 +168,12 @@ MouseInputDevice::Start(const char *name, void *cookie) status_t -MouseInputDevice::Stop(const char *device, void *cookie) +MouseInputDevice::Stop(const char *name, void *cookie) { - fputs("Stop()\n", fLogFile); + char log[128]; + snprintf(log, 128, "Stop(%s)\n", name); + + LOG(log); suspend_thread(fThread); @@ -164,7 +185,10 @@ status_t MouseInputDevice::Control(const char *name, void *cookie, uint32 command, BMessage *message) { - fputs("Control()\n", fLogFile); + char log[128]; + snprintf(log, 128, "Control(%s, code: %lu)\n", name, command); + + LOG(log); if (command == B_NODE_MONITOR) HandleMonitor(message); @@ -194,18 +218,51 @@ MouseInputDevice::DeviceWatcher(void *arg) ioctl(dev->fFd, kGetMouseMovements, &movements); // TODO: send B_MOUSE_UP/B_MOUSE_DOWN messages - - message = new BMessage(B_MOUSE_MOVED); - if (message) { - message->AddInt32("buttons", movements.buttons); - message->AddInt32("x", movements.xdelta); - message->AddInt32("y", movements.ydelta); - snprintf(log, 128, "buttons: %ld, x: %ld, y: %ld\n", + int32 buttons = dev->fButtons - movements.buttons; + + snprintf(log, 128, "buttons: %ld, x: %ld, y: %ld\n", movements.buttons, movements.xdelta, movements.ydelta); - fputs(log, dev->fLogFile); + LOG(log); + + // TODO: B_MOUSE_DOWN and B_MOUSE_UP messages don't seem + // to reach the application, + // for some reason. Check if they reach the input server. + if (buttons != 0) { + message = new BMessage; + if (buttons < 0) { + buttons = -buttons; + message->what = B_MOUSE_DOWN; + LOG("B_MOUSE_DOWN\n"); + } else if (buttons > 0) { + message->what = B_MOUSE_UP; + LOG("B_MOUSE_UP\n"); + } + + message->AddInt64("when", movements.mouse_time); + message->AddInt32("buttons", buttons); + message->AddInt32("clicks", movements.click_count); + // TODO: do we need to add the "where" field ? + // I guess not, as the input server will probably know the + // cursor position + dev->EnqueueMessage(message); + + dev->fButtons = movements.buttons; + + } + + if (movements.xdelta != 0 || movements.ydelta != 0) { + message = new BMessage(B_MOUSE_MOVED); + if (message) { + message->AddInt64("when", movements.mouse_time); + message->AddInt32("buttons", movements.buttons); + message->AddInt32("x", movements.xdelta); + message->AddInt32("y", movements.ydelta); + + dev->EnqueueMessage(message); + } } snooze(1000); } diff --git a/src/add-ons/input_server/devices/mouse/MouseInputDevice.h b/src/add-ons/input_server/devices/mouse/MouseInputDevice.h index 7df94ca77c..d58dc5374c 100644 --- a/src/add-ons/input_server/devices/mouse/MouseInputDevice.h +++ b/src/add-ons/input_server/devices/mouse/MouseInputDevice.h @@ -29,7 +29,9 @@ #include #include + #include +#include // TODO : these structs are needed in : input_server, mouse driver, mouse addon, mouse prefs // => factorisation has to be done in a global header, possibly private @@ -68,11 +70,12 @@ private: thread_id fThread; int fFd; bool fQuit; - FILE *fLogFile; - - static int32 DeviceWatcher(void *arg); - + mouse_settings fSettings; + + static FILE *sLogFile; + + static int32 DeviceWatcher(void *arg); }; extern "C" BInputServerDevice *instantiate_input_device();