Added mouse settings handling.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8779 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-09-01 15:55:54 +00:00
parent d5b3917b25
commit 53d77642d6
2 changed files with 84 additions and 3 deletions

View File

@ -30,6 +30,11 @@
#include <unistd.h>
const static uint32 kGetMouseMovements = 10099;
const static uint32 kGetMouseAccel = 10101;
const static uint32 kSetMouseAccel = 10102;
const static uint32 kSetMouseType = 10104;
const static uint32 kSetMouseMap = 10106;
const static uint32 kSetClickSpeed = 10108;
struct mouse_movement {
int32 ser_fd_index;
@ -51,8 +56,9 @@ instantiate_input_device()
MouseInputDevice::MouseInputDevice()
: fThread(-1),
fQuit(false)
{
fQuit = false;
fFd = open("dev/input/mouse/ps2/0", O_RDWR);
if (fFd >= 0)
fThread = spawn_thread(DeviceWatcher, "mouse watcher thread",
@ -76,9 +82,49 @@ MouseInputDevice::~MouseInputDevice()
}
status_t
MouseInputDevice::InitFromSettings(uint32 opcode)
{
// retrieve current values
if (get_mouse_map(&fSettings.map)!=B_OK)
fprintf(stderr, "error when get_mouse_map\n");
else
ioctl(fFd, kSetMouseMap, &fSettings.map);
if (get_click_speed(&fSettings.click_speed)!=B_OK)
fprintf(stderr, "error when get_click_speed\n");
else
ioctl(fFd, kSetClickSpeed, &fSettings.click_speed);
if (get_mouse_speed(&fSettings.accel.speed)!=B_OK)
fprintf(stderr, "error when get_mouse_speed\n");
else {
if (get_mouse_acceleration(&fSettings.accel.accel_factor)!=B_OK)
fprintf(stderr, "error when get_mouse_acceleration\n");
else {
mouse_accel accel;
ioctl(fFd, kGetMouseAccel, &accel);
accel.speed = fSettings.accel.speed;
accel.accel_factor = fSettings.accel.accel_factor;
ioctl(fFd, kSetMouseAccel, &fSettings.accel);
}
}
if (get_mouse_type(&fSettings.type)!=B_OK)
fprintf(stderr, "error when get_mouse_type\n");
else
ioctl(fFd, kSetMouseType, &fSettings.type);
return B_OK;
}
status_t
MouseInputDevice::InitCheck()
{
InitFromSettings();
input_device_ref mouse1 = { "Mouse 1", B_POINTING_DEVICE, (void *)this };
input_device_ref *devices[2] = { &mouse1, NULL };
@ -119,6 +165,20 @@ MouseInputDevice::Control(const char *name, void *cookie,
uint32 command, BMessage *message)
{
fputs("Control()\n", fLogFile);
if (command == B_NODE_MONITOR)
HandleMonitor(message);
else if (command >= B_MOUSE_TYPE_CHANGED
&& command <= B_MOUSE_ACCELERATION_CHANGED) {
InitFromSettings(command);
}
return B_OK;
}
status_t
MouseInputDevice::HandleMonitor(BMessage *message)
{
return B_OK;
}

View File

@ -28,9 +28,25 @@
#define __MOUSEINPUTDEVICE_H
#include <InputServerDevice.h>
#include <InterfaceDefs.h>
#include <stdio.h>
// 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
typedef struct {
bool enabled; // Acceleration on / off
int32 accel_factor; // accel factor: 256 = step by 1, 128 = step by 1/2
int32 speed; // speed accelerator (1=1X, 2 = 2x)...
} mouse_accel;
typedef struct {
int32 type;
mouse_map map;
mouse_accel accel;
bigtime_t click_speed;
} mouse_settings;
class MouseInputDevice : public BInputServerDevice {
public:
MouseInputDevice();
@ -44,6 +60,9 @@ public:
virtual status_t Control(const char *name, void *cookie,
uint32 command, BMessage *message);
private:
status_t HandleMonitor(BMessage *message);
status_t InitFromSettings(uint32 opcode = 0);
int32 fButtons;
thread_id fThread;
@ -52,6 +71,8 @@ private:
FILE *fLogFile;
static int32 DeviceWatcher(void *arg);
mouse_settings fSettings;
};
extern "C" BInputServerDevice *instantiate_input_device();