This fixes bug #149.

Input server now saves keyboard typematic settings whenever they are modified,
instead of wating until it is shutdown (which never happens, either the
system will crash, or the input_server will stay active after a normal shut down)
Same problems might apply to mouse and keymap settings.
Input server shutdown handling should be reviewed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16380 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen
2006-02-13 17:35:05 +00:00
parent 058070254d
commit fbe9b0b6eb
8 changed files with 110 additions and 92 deletions
@@ -14,6 +14,9 @@ typedef struct {
int32 key_repeat_rate;
} kb_settings;
#define kb_default_key_repeat_delay 500000
#define kb_default_key_repeat_rate 200
#define kb_settings_file "Keyboard_settings"
typedef struct {
+1 -2
View File
@@ -11,7 +11,6 @@
#include "KeyboardWindow.h"
#include "KeyboardMessages.h"
const char KeyboardApplication::kKeyboardApplicationSig[] = "application/x-vnd.Haiku-KeyboardPrefs";
int main(int, char**)
{
@@ -23,7 +22,7 @@ int main(int, char**)
}
KeyboardApplication::KeyboardApplication()
:BApplication(kKeyboardApplicationSig)
: BApplication("application/x-vnd.Haiku-KeyboardPrefs")
{
new KeyboardWindow();
-2
View File
@@ -18,8 +18,6 @@ public:
void MessageReceived(BMessage *message);
void AboutRequested(void);
private:
static const char kKeyboardApplicationSig[];
};
#endif
+46 -41
View File
@@ -1,63 +1,68 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Copyright 2004-2006, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : mccall@digitalparadise.co.uk, Jérôme Duval
** Authors in chronological order:
** [email protected]
** Jérôme Duval
** Marcus Overhagen
*/
#include <Application.h>
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <String.h>
#include <stdio.h>
#include "KeyboardSettings.h"
#include "KeyboardMessages.h"
// Keyboard setting file layout is like this:
// struct {
// struct kb_settings; // managed by input server
// BPoint corner; // used by pref app
// }
KeyboardSettings::KeyboardSettings()
{
if (get_key_repeat_rate(&fSettings.key_repeat_rate)!=B_OK)
fprintf(stderr, "error while get_key_repeat_rate!\n");
if (get_key_repeat_delay(&fSettings.key_repeat_delay)!=B_OK)
fprintf(stderr, "error while get_key_repeat_delay!\n");
fCorner.x = 50;
fCorner.y = 50;
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
path.Append(kb_settings_file);
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
// Now read in the data
if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK)
fSettings.key_repeat_rate = kb_default_key_repeat_rate;
if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK)
fSettings.key_repeat_delay = kb_default_key_repeat_delay;
file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(BPoint));
}
} else
be_app->PostMessage(ERROR_DETECTED);
fOriginalSettings = fSettings;
BPath path;
BFile file;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
goto err;
if (path.Append(kb_settings_file) < B_OK)
goto err;
if (file.SetTo(path.Path(), B_READ_ONLY) < B_OK)
goto err;
if (file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(fCorner)) != sizeof(fCorner))
goto err;
return;
err:
fCorner.x = 150;
fCorner.y = 100;
}
KeyboardSettings::~KeyboardSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
return;
path.Append(kb_settings_file);
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
if (file.InitCheck() == B_OK) {
file.WriteAt(sizeof(kb_settings), &fCorner, sizeof(BPoint));
}
BFile file;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
return;
if (path.Append(kb_settings_file) < B_OK)
return;
// be careful: don't create the file if it doesn't already exist
if (file.SetTo(path.Path(), B_WRITE_ONLY) < B_OK)
return;
file.WriteAt(sizeof(kb_settings), &fCorner, sizeof(fCorner));
}
@@ -71,7 +76,7 @@ KeyboardSettings::SetWindowCorner(BPoint corner)
void
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
{
if (set_key_repeat_rate(rate)!=B_OK)
if (set_key_repeat_rate(rate) != B_OK)
fprintf(stderr, "error while set_key_repeat_rate!\n");
fSettings.key_repeat_rate = rate;
}
@@ -80,7 +85,7 @@ KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
void
KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay)
{
if (set_key_repeat_delay(delay)!=B_OK)
if (set_key_repeat_delay(delay) != B_OK)
fprintf(stderr, "error while set_key_repeat_delay!\n");
fSettings.key_repeat_delay = delay;
}
@@ -105,6 +110,6 @@ KeyboardSettings::Revert()
void
KeyboardSettings::Defaults()
{
SetKeyboardRepeatDelay(250000);
SetKeyboardRepeatRate(200);
SetKeyboardRepeatDelay(kb_default_key_repeat_delay);
SetKeyboardRepeatRate(kb_default_key_repeat_rate);
}
@@ -32,7 +32,6 @@ public :
void SetKeyboardRepeatDelay(bigtime_t delay);
private:
static const char kKeyboardSettingsFile[];
BPoint fCorner;
kb_settings fSettings;
kb_settings fOriginalSettings;
+2
View File
@@ -137,6 +137,8 @@ InputServer::InputServer()
: BApplication(INPUTSERVER_SIGNATURE),
fSafeMode(false),
fInputDeviceListLocker("input server device list"),
fKeyboardSettings(),
fMouseSettings(),
fChars(NULL),
fScreen(B_MAIN_SCREEN_ID),
fInputMethodWindow(NULL),
+41 -34
View File
@@ -1,53 +1,41 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Copyright 2004-2006, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: [email protected]
** Authors in chronological order:
** [email protected]
** Jérôme Duval
** Marcus Overhagen
*/
#include <Application.h>
#include <FindDirectory.h>
#include <File.h>
#include <Path.h>
#include <String.h>
#include <stdio.h>
#include "KeyboardSettings.h"
KeyboardSettings::KeyboardSettings()
{
fSettings.key_repeat_delay=200;
fSettings.key_repeat_rate=250000;
BPath path;
BFile file;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
path.Append(kb_settings_file);
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;
}
}
}
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
goto err;
if (path.Append(kb_settings_file) < B_OK)
goto err;
if (file.SetTo(path.Path(), B_READ_ONLY) < B_OK)
goto err;
if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings))
goto err;
return;
err:
fSettings.key_repeat_delay = kb_default_key_repeat_delay;
fSettings.key_repeat_rate = kb_default_key_repeat_rate;
}
KeyboardSettings::~KeyboardSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
return;
path.Append(kb_settings_file);
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
if (file.InitCheck() == B_OK) {
file.Write(&fSettings, sizeof(kb_settings));
}
}
@@ -55,11 +43,30 @@ void
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
{
fSettings.key_repeat_rate = rate;
Save();
}
void
KeyboardSettings::SetKeyboardRepeatDelay(int32 rate)
KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay)
{
fSettings.key_repeat_delay = rate;
fSettings.key_repeat_delay = delay;
Save();
}
void
KeyboardSettings::Save()
{
BPath path;
BFile file;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
return;
if (path.Append(kb_settings_file) < B_OK)
return;
if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE) < B_OK)
return;
file.Write(&fSettings, sizeof(kb_settings));
}
+17 -12
View File
@@ -1,9 +1,11 @@
/*
** Copyright 2004, the Haiku project. All rights reserved.
** Copyright 2004-2006, the Haiku project. All rights reserved.
** Distributed under the terms of the Haiku License.
**
** Author : Jérôme Duval
** Original authors: [email protected]
** Authors in chronological order:
** [email protected]
** Jérôme Duval
** Marcus Overhagen
*/
#ifndef KEYBOARD_SETTINGS_H_
@@ -12,19 +14,22 @@
#include <SupportDefs.h>
#include <kb_mouse_settings.h>
class KeyboardSettings {
class KeyboardSettings
{
public :
KeyboardSettings();
~KeyboardSettings();
KeyboardSettings();
~KeyboardSettings();
void SetKeyboardRepeatRate(int32 rate);
void SetKeyboardRepeatDelay(bigtime_t delay);
int32 KeyboardRepeatRate() const { return fSettings.key_repeat_rate; }
void SetKeyboardRepeatRate(int32 rate);
int32 KeyboardRepeatDelay() const { return fSettings.key_repeat_delay; }
void SetKeyboardRepeatDelay(int32 rate);
int32 KeyboardRepeatRate() const { return fSettings.key_repeat_rate; }
bigtime_t KeyboardRepeatDelay() const { return fSettings.key_repeat_delay; }
private:
void Save();
private:
static const char kKeyboardSettingsFile[];
BPoint fCorner;
kb_settings fSettings;
};