Integrated MouseSettings and KeyboardSettings

update license info
clean up
removed node monitoring messages handling
fixed several message handlers


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8710 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2004-08-29 15:20:34 +00:00
parent 970f7be9fb
commit 00740cc502
14 changed files with 500 additions and 405 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
/*
** Copyright 2004, the OpenBeOS project. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: Marcus Overhagen, Axel Dörfler
@@ -253,12 +253,12 @@ AddOnManager::RegisterAddOns()
const directory_which directories[] = {
B_USER_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_BEOS_ADDONS_DIRECTORY,
// B_BEOS_ADDONS_DIRECTORY
};
const char subDirectories[][24] = {
"input_server/devices",
"input_server/filters",
"input_server/methods",
"input_server/methods"
};
fHandler = new IAHandler(this);
fAddOnMonitor = new AddOnMonitor(fHandler);
+2 -2
View File
@@ -1,6 +1,6 @@
/*
** Copyright 2004, the OpenBeOS project. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: Marcus Overhagen, Axel Dörfler
+2 -2
View File
@@ -1,6 +1,6 @@
/*
** Copyright 2004, the OpenBeOS project. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: Marcus Overhagen, Axel Dörfler
+2 -2
View File
@@ -1,6 +1,6 @@
/*
** Copyright 2004, the OpenBeOS project. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: Marcus Overhagen, Axel Dörfler
+39 -354
View File
@@ -1,7 +1,5 @@
/*****************************************************************************/
// OpenBeOS InputServer
//
// Version: [0.0.5] [Development Stage]
// Haiku InputServer
//
// [Description]
//
@@ -10,7 +8,7 @@
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2002 OpenBeOS Project
// Copyright (c) 2002-2004 Haiku Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@@ -43,9 +41,6 @@
#include <String.h>
#include "InputServer.h"
#include "InputServerDeviceListEntry.h"
#include "InputServerFilterListEntry.h"
#include "InputServerMethodListEntry.h"
#include "InputServerTypes.h"
// include app_server headers for communication
@@ -159,314 +154,6 @@ InputServer::InitKeyboardMouseStates(void)
}
/*void
InputServer::InitTestDevice()
{
CALLED();
const char* path = "/boot/home/Projects/InputServer/ISD/nervous/nervous";
printf("InputServer::InitTestDevice - Loading add-on . . .\n");
image_id addon_image = load_add_on(path);
if (B_ERROR != addon_image)
{
status_t isd_status = B_NO_INIT;
BInputServerDevice* (*func)() = NULL;
printf("InputServer::InitTestDevice - Resolving symbol . . .\n");
if (B_OK == get_image_symbol(addon_image, "instantiate_input_device", B_SYMBOL_TYPE_TEXT, (void**)&func) )
{
printf("Found instantiate_input_device.\n");
if (NULL != func)
{
BInputServerDevice* isd = (*func)();
if (NULL != isd)
{
printf("InputServer::InitTestDevice - Calling InitCheck . . .\n");
isd_status = isd->InitCheck();
mInputServerDeviceList.AddItem(
new InputServerDeviceListEntry(path, isd_status, isd) );
if (B_OK == isd_status)
{
//printf("Starting Nervous . . .\n");
//isd->Start("Nervous Device", NULL);
}
else
{
printf("InitCheck failed.\n");
}
}
}
}
if (B_OK != isd_status)
{
// Free resources associated with ISD's
// that failed to initialize.
//
//unload_add_on(addon_image);
}
}
EXIT();
}*/
/*
* Method: InputServer::InitDevices()
* Descr:
*/
/*void
InputServer::InitDevices(void)
{
CALLED();
BDirectory dir;
BPath addon_dir;
BPath addon_path;
BEntry entry;
directory_which addon_dirs[] =
{
B_BEOS_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY
};
const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which);
// Find all Input Server Devices in each of the predefined
// addon directories.
//
for (int i = 0; i < addon_dir_count; i++)
{
if (B_OK == find_directory(addon_dirs[i], &addon_dir) )
{
addon_dir.Append("input_server/devices");
dir.SetTo(addon_dir.Path() );
while (B_NO_ERROR == dir.GetNextEntry(&entry, false) )
{
entry.GetPath(&addon_path);
printf("Adding %s . . .\n", addon_path.Path() );
AddInputServerDevice(addon_path.Path() );
}
}
}
EXIT();
}*/
/*
* Method: InputServer::AddInputServerDevice()
* Descr:
*/
/*status_t
InputServer::AddInputServerDevice(const char* path)
{
image_id addon_image= load_add_on(path);
if (B_ERROR != addon_image)
{
status_t isd_status = B_NO_INIT;
BInputServerDevice* (*func)() = NULL;
if (B_OK == get_image_symbol(addon_image, "instantiate_input_device", B_SYMBOL_TYPE_TEXT, (void**)&func) )
{
if (NULL != func)
{
/*
// :DANGER: Only reenable this section if this
// InputServer can start and manage the
// devices, otherwise the system will hang.
//
BInputServerDevice* isd = (*func)();
if (NULL != isd)
{
isd_status = isd->InitCheck();
mInputServerDeviceList.AddItem(
new InputServerDeviceListEntry(path, isd_status, isd) );
}
*/
/*mInputServerDeviceList.AddItem(
new InputServerDeviceListEntry(path, B_NO_INIT, NULL) );
}
}
if (B_OK != isd_status)
{
// Free resources associated with ISD's
// that failed to initialize.
//
unload_add_on(addon_image);
}
}
return 0;
}*/
/*
* Method: InputServer::InitFilters()
* Descr:
*/
/*void
InputServer::InitFilters(void)
{
CALLED();
BDirectory dir;
BPath addon_dir;
BPath addon_path;
BEntry entry;
directory_which addon_dirs[] =
{
B_BEOS_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY
};
const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which);
// Find all Input Filters in each of the predefined
// addon directories.
//
for (int i = 0; i < addon_dir_count; i++)
{
if (B_OK == find_directory(addon_dirs[i], &addon_dir) )
{
addon_dir.Append("input_server/filters");
dir.SetTo(addon_dir.Path() );
while (B_NO_ERROR == dir.GetNextEntry(&entry, false) )
{
entry.GetPath(&addon_path);
printf("Adding %s . . .\n", addon_path.Path() );
AddInputServerFilter(addon_path.Path() );
}
}
}
EXIT();
}*/
/*
* Method: InputServer::AddInputServerFilter()
* Descr:
*/
/*status_t
InputServer::AddInputServerFilter(const char* path)
{
image_id addon_image= load_add_on(path);
if (B_ERROR != addon_image)
{
status_t isf_status = B_NO_INIT;
BInputServerFilter* (*func)() = NULL;
if (B_OK == get_image_symbol(addon_image, "instantiate_input_filter", B_SYMBOL_TYPE_TEXT, (void**)&func) )
{
if (NULL != func)
{
/*
// :DANGER: Only reenable this section if this
// InputServer can start and manage the
// filters, otherwise the system will hang.
//
BInputFilter isf = (*func)();
if (NULL != isf)
{
isf_status = isf->InitCheck();
mInputServerFilterList.AddItem(
new InputServerFilterListEntry(path, isf_status, isf );
}
*/
/*mInputServerFilterList.AddItem(
new InputServerFilterListEntry(path, B_NO_INIT, NULL) );
}
}
if (B_OK != isf_status)
{
// Free resources associated with InputServerFilters
// that failed to initialize.
//
unload_add_on(addon_image);
}
}
return 0;
}*/
/*
* Method: InputServer::InitMethods()
* Descr:
*/
/*void
InputServer::InitMethods(void)
{
CALLED();
BDirectory dir;
BPath addon_dir;
BPath addon_path;
BEntry entry;
directory_which addon_dirs[] =
{
B_BEOS_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_USER_ADDONS_DIRECTORY
};
const int addon_dir_count = sizeof(addon_dirs) / sizeof(directory_which);
// Find all Input Methods in each of the predefined
// addon directories.
//
for (int i = 0; i < addon_dir_count; i++)
{
if (B_OK == find_directory(addon_dirs[i], &addon_dir) )
{
addon_dir.Append("input_server/methods");
dir.SetTo(addon_dir.Path() );
while (B_NO_ERROR == dir.GetNextEntry(&entry, false) )
{
entry.GetPath(&addon_path);
printf("Adding %s . . .\n", addon_path.Path() );
AddInputServerMethod(addon_path.Path() );
}
}
}
EXIT();
}*/
/*
* Method: InputServer::AddInputServerMethod()
* Descr:
*/
/*status_t
InputServer::AddInputServerMethod(const char* path)
{
image_id addon_image= load_add_on(path);
if (B_ERROR != addon_image)
{
status_t ism_status = B_NO_INIT;
BInputServerMethod* (*func)() = NULL;
if (B_OK == get_image_symbol(addon_image, "instantiate_input_method", B_SYMBOL_TYPE_TEXT, (void**)&func) )
{
if (NULL != func)
{
/*
// :DANGER: Only reenable this section if this
// InputServer can start and manage the
// methods, otherwise the system will hang.
//
BInputServerMethod ism = (*func)();
if (NULL != ism)
{
ism_status = ism->InitCheck();
mInputServerMethodList.AddItem(
new InputServerMethodListEntry(path, ism_status, ism) );
}
*/
/*mInputServerMethodList.AddItem(
new InputServerMethodListEntry(path, B_NO_INIT, NULL) );
}
}
if (B_OK != ism_status)
{
// Free resources associated with InputServerMethods
// that failed to initialize.
//
unload_add_on(addon_image);
}
}
return 0;
}*/
/*
* Method: InputServer::QuitRequested()
@@ -618,12 +305,6 @@ InputServer::MessageReceived(BMessage *message)
case SYSTEM_SHUTTING_DOWN:
status = HandleSystemShuttingDown(message, &reply);
break;
case B_NODE_MONITOR:
status = HandleNodeMonitor(message);
break;
/*case B_QUIT_REQUESTED:
QuitRequested();
break;*/
default:
{
PRINT(("Default message ... \n"));
@@ -660,10 +341,12 @@ InputServer::HandleGetSetMouseType(BMessage* message,
BMessage* reply)
{
status_t status;
if (message->FindInt32("mouse_type", &sMouseType)==B_OK)
int32 type;
if (message->FindInt32("mouse_type", &type)==B_OK) {
fMouseSettings.SetMouseType(type);
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_TYPE_CHANGED, NULL);
else
status = reply->AddInt32("mouse_type", sMouseType);
} else
status = reply->AddInt32("mouse_type", fMouseSettings.MouseType());
return status;
}
@@ -677,10 +360,12 @@ InputServer::HandleGetSetMouseAcceleration(BMessage* message,
BMessage* reply)
{
status_t status;
if (message->FindInt32("mouse_acceleration", &sMouseAcceleration) == B_OK)
int32 factor;
if (message->FindInt32("speed", &factor) == B_OK) {
fMouseSettings.SetAccelerationFactor(factor);
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_ACCELERATION_CHANGED, NULL);
else
status = reply->AddInt32("mouse_acceleration", sMouseAcceleration);
} else
status = reply->AddInt32("speed", fMouseSettings.AccelerationFactor());
return status;
}
@@ -694,10 +379,12 @@ InputServer::HandleGetSetKeyRepeatDelay(BMessage* message,
BMessage* reply)
{
status_t status;
if (message->FindInt64("key_repeat_delay", &sKeyRepeatDelay) == B_OK)
bigtime_t delay;
if (message->FindInt64("delay", &delay) == B_OK) {
fKeyboardSettings.SetKeyboardRepeatDelay(delay);
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_DELAY_CHANGED, NULL);
else
status = reply->AddInt64("key_repeat_delay", sKeyRepeatDelay);
} else
status = reply->AddInt64("delay", fKeyboardSettings.KeyboardRepeatDelay());
return status;
}
@@ -773,10 +460,12 @@ InputServer::HandleGetSetMouseSpeed(BMessage* message,
BMessage* reply)
{
status_t status;
if (message->FindInt32("mouse_speed", &sMouseSpeed) == B_OK)
int32 speed;
if (message->FindInt32("speed", &speed) == B_OK) {
fMouseSettings.SetMouseSpeed(speed);
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_SPEED_CHANGED, NULL);
else
status = reply->AddInt32("mouse_speed", sMouseSpeed);
} else
status = reply->AddInt32("speed", fMouseSettings.MouseSpeed());
return status;
}
@@ -836,11 +525,14 @@ InputServer::HandleGetSetMouseMap(BMessage* message,
mouse_map *map;
ssize_t size;
if (message->FindData("mouse_map", B_RAW_TYPE, (const void**)&map, &size) == B_OK) {
memcpy(&sMouseMap, map, sizeof(sMouseMap) );
if (message->FindData("mousemap", B_RAW_TYPE, (const void**)&map, &size) == B_OK) {
fMouseSettings.SetMapping(*map);
status = ControlDevices(NULL, B_POINTING_DEVICE, B_MOUSE_MAP_CHANGED, NULL);
} else
status = reply->AddData("mouse_map", B_RAW_TYPE, &sMouseMap, sizeof(sMouseMap) );
} else {
mouse_map map;
fMouseSettings.Mapping(map);
status = reply->AddData("mousemap", B_RAW_TYPE, &map, sizeof(mouse_map) );
}
return status;
}
@@ -866,10 +558,12 @@ InputServer::HandleGetSetClickSpeed(BMessage *message,
BMessage *reply)
{
status_t status = B_ERROR;
if (message->FindInt64("mouse_click_speed", &sMouseClickSpeed) == B_OK)
bigtime_t click_speed;
if (message->FindInt64("speed", &click_speed) == B_OK) {
fMouseSettings.SetClickSpeed(click_speed);
status = ControlDevices(NULL, B_POINTING_DEVICE, B_CLICK_SPEED_CHANGED, NULL);
else
status = reply->AddInt64("mouse_click_speed", sMouseClickSpeed);
} else
status = reply->AddInt64("speed", fMouseSettings.ClickSpeed());
return status;
}
@@ -883,10 +577,12 @@ InputServer::HandleGetSetKeyRepeatRate(BMessage* message,
BMessage* reply)
{
status_t status;
if (message->FindInt32("key_repeat_rate", &sKeyRepeatRate) == B_OK)
int32 key_repeat_rate;
if (message->FindInt32("rate", &key_repeat_rate) == B_OK) {
fKeyboardSettings.SetKeyboardRepeatRate(key_repeat_rate);
status = ControlDevices(NULL, B_KEYBOARD_DEVICE, B_KEY_REPEAT_RATE_CHANGED, NULL);
else
status = reply->AddInt32("key_repeat_rate", sKeyRepeatRate);
} else
status = reply->AddInt32("rate", fKeyboardSettings.KeyboardRepeatRate());
return status;
}
@@ -994,17 +690,6 @@ InputServer::HandleSystemShuttingDown(BMessage *message,
}
/*
* Method: InputServer::HandleNodeMonitor()
* Descr:
*/
status_t
InputServer::HandleNodeMonitor(BMessage *message)
{
}
/*
* Method: InputServer::EnqueueDeviceMessage()
* Descr:
+8 -24
View File
@@ -1,10 +1,10 @@
/*****************************************************************************/
// OpenBeOS input_server Backend Application
// Haiku input_server
//
// This is the primary application class for the OpenBeOS input_server.
// This is the primary application class for the Haiku input_server.
//
//
// Copyright (c) 2001 OpenBeOS Project
// Copyright (c) 2001-2004 Haiku Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
@@ -36,6 +36,8 @@
#include <InputServerMethod.h>
#include "AddOnManager.h"
#include "DeviceManager.h"
#include "MouseSettings.h"
#include "KeyboardSettings.h"
#include <stdlib.h>
#include <string.h>
@@ -107,10 +109,6 @@ public:
virtual void ArgvReceived(long, char**);
void InitKeyboardMouseStates(void);
//void InitDevices(void);
//void InitFilters(void);
//void InitMethods(void);
virtual bool QuitRequested(void);
virtual void ReadyToRun(void);
@@ -184,25 +182,15 @@ public:
static DeviceManager gDeviceManager;
private:
/*void InitTestDevice();
status_t AddInputServerDevice(const char* path);
status_t AddInputServerFilter(const char* path);
status_t AddInputServerMethod(const char* path);*/
bool sEventLoopRunning;
bool sSafeMode;
port_id sEventPort;
BPoint sMousePos;
int32 sMouseType;
int32 sMouseSpeed;
int32 sMouseAcceleration;
bigtime_t sMouseClickSpeed;
int32 sKeyRepeatRate;
bigtime_t sKeyRepeatDelay;
int32 sKeyboardLocks;
uint16 sKeyboardID;
mouse_map sMouseMap;
KeyboardSettings fKeyboardSettings;
MouseSettings fMouseSettings;
key_info s_key_info; // current key info
key_map s_key_map; // current key_map
@@ -217,10 +205,6 @@ private:
static bool doStartStopDevice(void*, void*);
//static BList mInputServerDeviceList;
//static BList mInputServerFilterList;
//static BList mInputServerMethodList;
// added this to communicate via portlink
BPortLink *serverlink;
+3 -6
View File
@@ -1,16 +1,13 @@
/*****************************************************************************/
// OpenBeOS InputServer
//
// Version: [0.0.5] [Development Stage]
//
// [Description]
// Haiku InputServer
//
// This is the InputServerDevice implementation
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2002 OpenBeOS Project
// Copyright (c) 2002-2004 Haiku Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
+3 -5
View File
@@ -1,16 +1,14 @@
/*****************************************************************************/
// OpenBeOS InputServer
// Haiku InputServer
//
// Version: [0.0.5] [Development Stage]
//
// [Description]
// This is the InputServerFilter implementation
//
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2002 OpenBeOS Project
// Copyright (c) 2002-2004 Haiku Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
+3 -6
View File
@@ -1,16 +1,13 @@
/*****************************************************************************/
// OpenBeOS InputServer
//
// Version: [0.0.5] [Development Stage]
//
// [Description]
// Haiku InputServer
//
// This is the InputServerMethod implementation
//
// This application and all source files used in its construction, except
// where noted, are licensed under the MIT License, and have been written
// and are:
//
// Copyright (c) 2002 OpenBeOS Project
// Copyright (c) 2002-2004 Haiku Project
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
+3
View File
@@ -19,6 +19,9 @@ Server input_server :
AddOnManager.cpp
DeviceManager.cpp
MouseSettings.cpp
KeyboardSettings.cpp
# storage
AddOnMonitor.cpp
AddOnMonitorHandler.cpp
+67
View File
@@ -0,0 +1,67 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: mccall@digitalparadise.co.uk
*/
#include <Application.h>
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <String.h>
#include <stdio.h>
#include "KeyboardSettings.h"
const char KeyboardSettings::kKeyboardSettingsFile[] = "Keyboard_settings";
KeyboardSettings::KeyboardSettings()
{
fSettings.key_repeat_delay=200;
fSettings.key_repeat_rate=250000;
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
path.Append(kKeyboardSettingsFile);
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
// Now read in the data
if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings)) {
fSettings.key_repeat_delay=200;
fSettings.key_repeat_rate=250000;
}
}
}
}
KeyboardSettings::~KeyboardSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
return;
path.Append(kKeyboardSettingsFile);
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
if (file.InitCheck() == B_OK) {
file.Write(&fSettings, sizeof(kb_settings));
}
}
void
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
{
fSettings.key_repeat_rate = rate;
}
void
KeyboardSettings::SetKeyboardRepeatDelay(int32 rate)
{
fSettings.key_repeat_delay = rate;
}
+35
View File
@@ -0,0 +1,35 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: mccall@digitalparadise.co.uk
*/
#ifndef KEYBOARD_SETTINGS_H_
#define KEYBOARD_SETTINGS_H_
#include <SupportDefs.h>
typedef struct {
bigtime_t key_repeat_delay;
int32 key_repeat_rate;
} kb_settings;
class KeyboardSettings {
public :
KeyboardSettings();
~KeyboardSettings();
int32 KeyboardRepeatRate() const { return fSettings.key_repeat_rate; }
void SetKeyboardRepeatRate(int32 rate);
int32 KeyboardRepeatDelay() const { return fSettings.key_repeat_delay; }
void SetKeyboardRepeatDelay(int32 rate);
private:
static const char kKeyboardSettingsFile[];
BPoint fCorner;
kb_settings fSettings;
};
#endif
+250
View File
@@ -0,0 +1,250 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2004, Haiku
//
// This software is part of the Haiku distribution and is covered
// by the Haiku license.
//
//
// File: MouseSettings.h
// Authors: Jérôme Duval,
// Andrew McCall ([email protected]),
// Axel Dörfler ([email protected])
// Description: Input Server
// Created: August 29, 2004
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <View.h>
#include <stdio.h>
#include "MouseSettings.h"
static const char kMouseSettingsFile[] = "Mouse_settings";
static const bigtime_t kDefaultClickSpeed = 500000;
static const int32 kDefaultMouseSpeed = 65536;
static const int32 kDefaultMouseType = 3; // 3 button mouse
static const int32 kDefaultAccelerationFactor = 65536;
MouseSettings::MouseSettings()
{
RetrieveSettings();
fOriginalSettings = fSettings;
fOriginalMode = fMode;
}
MouseSettings::~MouseSettings()
{
SaveSettings();
}
status_t
MouseSettings::GetSettingsPath(BPath &path)
{
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
if (status < B_OK)
return status;
path.Append(kMouseSettingsFile);
return B_OK;
}
void
MouseSettings::RetrieveSettings()
{
// retrieve current values
fMode = mouse_mode();
// also try to load the window position from disk
BPath path;
if (GetSettingsPath(path) < B_OK)
return;
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() < B_OK)
return;
#ifdef COMPILE_FOR_R5
// we have to do this because mouse_map counts 16 buttons in OBOS
if ((file.Read(&fSettings.type, sizeof(int32)) != sizeof(int32))
|| (file.Read(&fSettings.map, sizeof(int32) * 3) != sizeof(int32) * 3)
|| (file.Read(&fSettings.accel, sizeof(mouse_accel)) != sizeof(mouse_accel))
|| (file.Read(&fSettings.click_speed, sizeof(bigtime_t)) != sizeof(bigtime_t))) {
Defaults();
}
#else
if (file.ReadAt(0, &fSettings, sizeof(mouse_settings)) != sizeof(mouse_settings)) {
Defaults();
}
#endif
#ifdef DEBUG
Dump();
#endif
}
status_t
MouseSettings::SaveSettings()
{
#ifdef DEBUG
Dump();
#endif
BPath path;
status_t status = GetSettingsPath(path);
if (status < B_OK)
return status;
BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE);
if (status < B_OK)
return status;
// we have to do this because mouse_map counts 16 buttons in OBOS
#ifdef COMPILE_FOR_R5
file.Write(&fSettings.type, sizeof(fSettings.type));
file.Write(&fSettings.map, 3*sizeof(int32));
file.Write(&fSettings.accel, sizeof(fSettings.accel));
file.Write(&fSettings.click_speed, sizeof(fSettings.click_speed));
#else
file.Write(fSettings, sizeof(fSettings));
#endif
// who is responsible for saving the mouse mode?
return B_OK;
}
#ifdef DEBUG
void
MouseSettings::Dump()
{
printf("type:\t\t%ld button mouse\n", fSettings.type);
printf("map:\t\tleft = %lu : middle = %lu : right = %lu\n", fSettings.map.button[0], fSettings.map.button[2], fSettings.map.button[1]);
printf("click speed:\t%Ld\n", fSettings.click_speed);
printf("accel:\t\t%s\n", fSettings.accel.enabled ? "enabled" : "disabled");
printf("accel factor:\t%ld\n", fSettings.accel.accel_factor);
printf("speed:\t\t%ld\n", fSettings.accel.speed);
char *mode = "unknown";
switch (fMode) {
case B_NORMAL_MOUSE:
mode = "normal";
break;
case B_FOCUS_FOLLOWS_MOUSE:
mode = "focus follows mouse";
break;
case B_WARP_MOUSE:
mode = "warp mouse";
break;
case B_INSTANT_WARP_MOUSE:
mode = "instant warp mouse";
break;
}
printf("mode:\t\t%s\n", mode);
}
#endif
/** Resets the settings to the system defaults
*/
void
MouseSettings::Defaults()
{
SetClickSpeed(kDefaultClickSpeed);
SetMouseSpeed(kDefaultMouseSpeed);
SetMouseType(kDefaultMouseType);
SetAccelerationFactor(kDefaultAccelerationFactor);
SetMouseMode(B_NORMAL_MOUSE);
fSettings.map.button[0] = B_PRIMARY_MOUSE_BUTTON;
fSettings.map.button[1] = B_SECONDARY_MOUSE_BUTTON;
fSettings.map.button[2] = B_TERTIARY_MOUSE_BUTTON;
}
void
MouseSettings::SetMouseType(int32 type)
{
fSettings.type = type;
}
bigtime_t
MouseSettings::ClickSpeed() const
{
return fSettings.click_speed;
}
void
MouseSettings::SetClickSpeed(bigtime_t clickSpeed)
{
fSettings.click_speed = clickSpeed;
}
void
MouseSettings::SetMouseSpeed(int32 speed)
{
fSettings.accel.speed = speed;
}
void
MouseSettings::SetAccelerationFactor(int32 factor)
{
fSettings.accel.accel_factor = factor;
}
uint32
MouseSettings::Mapping(int32 index) const
{
return fSettings.map.button[index];
}
void
MouseSettings::Mapping(mouse_map &map) const
{
map = fSettings.map;
}
void
MouseSettings::SetMapping(int32 index, uint32 button)
{
fSettings.map.button[index] = button;
}
void
MouseSettings::SetMapping(mouse_map &map)
{
fSettings.map = map;
}
void
MouseSettings::SetMouseMode(mode_mouse mode)
{
fMode = mode;
}
+79
View File
@@ -0,0 +1,79 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2004, Haiku
//
// This software is part of the Haiku distribution and is covered
// by the Haiku license.
//
//
// File: MouseSettings.h
// Authors: Jérôme Duval,
// Andrew McCall ([email protected]),
// Axel Dörfler ([email protected])
// Description: Input Server
// Created: August 29, 2004
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#ifndef MOUSE_SETTINGS_H_
#define MOUSE_SETTINGS_H_
#include <SupportDefs.h>
#include <InterfaceDefs.h>
// ToDo: these should be defined somewhere else; the mouse
// input driver or add-on must read them as well
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 MouseSettings {
public:
MouseSettings();
~MouseSettings();
void Defaults();
void Dump();
int32 MouseType() const { return fSettings.type; }
void SetMouseType(int32 type);
bigtime_t ClickSpeed() const;
void SetClickSpeed(bigtime_t click_speed);
int32 MouseSpeed() const { return fSettings.accel.speed; }
void SetMouseSpeed(int32 speed);
int32 AccelerationFactor() const { return fSettings.accel.accel_factor; }
void SetAccelerationFactor(int32 factor);
uint32 Mapping(int32 index) const;
void Mapping(mouse_map &map) const;
void SetMapping(int32 index, uint32 button);
void SetMapping(mouse_map &map);
mode_mouse MouseMode() const { return fMode; }
void SetMouseMode(mode_mouse mode);
private:
static status_t GetSettingsPath(BPath &path);
void RetrieveSettings();
status_t SaveSettings();
mouse_settings fSettings, fOriginalSettings;
mode_mouse fMode, fOriginalMode;
};
#endif