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:
@@ -14,6 +14,9 @@ typedef struct {
|
|||||||
int32 key_repeat_rate;
|
int32 key_repeat_rate;
|
||||||
} kb_settings;
|
} kb_settings;
|
||||||
|
|
||||||
|
#define kb_default_key_repeat_delay 500000
|
||||||
|
#define kb_default_key_repeat_rate 200
|
||||||
|
|
||||||
#define kb_settings_file "Keyboard_settings"
|
#define kb_settings_file "Keyboard_settings"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "KeyboardWindow.h"
|
#include "KeyboardWindow.h"
|
||||||
#include "KeyboardMessages.h"
|
#include "KeyboardMessages.h"
|
||||||
|
|
||||||
const char KeyboardApplication::kKeyboardApplicationSig[] = "application/x-vnd.Haiku-KeyboardPrefs";
|
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
@@ -23,7 +22,7 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
KeyboardApplication::KeyboardApplication()
|
KeyboardApplication::KeyboardApplication()
|
||||||
:BApplication(kKeyboardApplicationSig)
|
: BApplication("application/x-vnd.Haiku-KeyboardPrefs")
|
||||||
{
|
{
|
||||||
|
|
||||||
new KeyboardWindow();
|
new KeyboardWindow();
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ public:
|
|||||||
void MessageReceived(BMessage *message);
|
void MessageReceived(BMessage *message);
|
||||||
|
|
||||||
void AboutRequested(void);
|
void AboutRequested(void);
|
||||||
private:
|
|
||||||
static const char kKeyboardApplicationSig[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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.
|
** 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 <FindDirectory.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "KeyboardSettings.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()
|
KeyboardSettings::KeyboardSettings()
|
||||||
{
|
{
|
||||||
if (get_key_repeat_rate(&fSettings.key_repeat_rate)!=B_OK)
|
if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK)
|
||||||
fprintf(stderr, "error while get_key_repeat_rate!\n");
|
fSettings.key_repeat_rate = kb_default_key_repeat_rate;
|
||||||
if (get_key_repeat_delay(&fSettings.key_repeat_delay)!=B_OK)
|
|
||||||
fprintf(stderr, "error while get_key_repeat_delay!\n");
|
if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK)
|
||||||
|
fSettings.key_repeat_delay = kb_default_key_repeat_delay;
|
||||||
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
|
|
||||||
|
|
||||||
file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(BPoint));
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
be_app->PostMessage(ERROR_DETECTED);
|
|
||||||
|
|
||||||
fOriginalSettings = fSettings;
|
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()
|
KeyboardSettings::~KeyboardSettings()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
|
BFile file;
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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
|
void
|
||||||
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
|
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");
|
fprintf(stderr, "error while set_key_repeat_rate!\n");
|
||||||
fSettings.key_repeat_rate = rate;
|
fSettings.key_repeat_rate = rate;
|
||||||
}
|
}
|
||||||
@@ -80,7 +85,7 @@ KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
|
|||||||
void
|
void
|
||||||
KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay)
|
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");
|
fprintf(stderr, "error while set_key_repeat_delay!\n");
|
||||||
fSettings.key_repeat_delay = delay;
|
fSettings.key_repeat_delay = delay;
|
||||||
}
|
}
|
||||||
@@ -105,6 +110,6 @@ KeyboardSettings::Revert()
|
|||||||
void
|
void
|
||||||
KeyboardSettings::Defaults()
|
KeyboardSettings::Defaults()
|
||||||
{
|
{
|
||||||
SetKeyboardRepeatDelay(250000);
|
SetKeyboardRepeatDelay(kb_default_key_repeat_delay);
|
||||||
SetKeyboardRepeatRate(200);
|
SetKeyboardRepeatRate(kb_default_key_repeat_rate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ public :
|
|||||||
void SetKeyboardRepeatDelay(bigtime_t delay);
|
void SetKeyboardRepeatDelay(bigtime_t delay);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char kKeyboardSettingsFile[];
|
|
||||||
BPoint fCorner;
|
BPoint fCorner;
|
||||||
kb_settings fSettings;
|
kb_settings fSettings;
|
||||||
kb_settings fOriginalSettings;
|
kb_settings fOriginalSettings;
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ InputServer::InputServer()
|
|||||||
: BApplication(INPUTSERVER_SIGNATURE),
|
: BApplication(INPUTSERVER_SIGNATURE),
|
||||||
fSafeMode(false),
|
fSafeMode(false),
|
||||||
fInputDeviceListLocker("input server device list"),
|
fInputDeviceListLocker("input server device list"),
|
||||||
|
fKeyboardSettings(),
|
||||||
|
fMouseSettings(),
|
||||||
fChars(NULL),
|
fChars(NULL),
|
||||||
fScreen(B_MAIN_SCREEN_ID),
|
fScreen(B_MAIN_SCREEN_ID),
|
||||||
fInputMethodWindow(NULL),
|
fInputMethodWindow(NULL),
|
||||||
|
|||||||
@@ -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.
|
** Distributed under the terms of the Haiku License.
|
||||||
**
|
**
|
||||||
** Author : Jérôme Duval
|
** Authors in chronological order:
|
||||||
** Original authors: [email protected]
|
** [email protected]
|
||||||
|
** Jérôme Duval
|
||||||
|
** Marcus Overhagen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Application.h>
|
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <String.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "KeyboardSettings.h"
|
#include "KeyboardSettings.h"
|
||||||
|
|
||||||
KeyboardSettings::KeyboardSettings()
|
KeyboardSettings::KeyboardSettings()
|
||||||
{
|
{
|
||||||
fSettings.key_repeat_delay=200;
|
|
||||||
fSettings.key_repeat_rate=250000;
|
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
|
BFile file;
|
||||||
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) {
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
||||||
path.Append(kb_settings_file);
|
goto err;
|
||||||
BFile file(path.Path(), B_READ_ONLY);
|
if (path.Append(kb_settings_file) < B_OK)
|
||||||
if (file.InitCheck() == B_OK) {
|
goto err;
|
||||||
// Now read in the data
|
if (file.SetTo(path.Path(), B_READ_ONLY) < B_OK)
|
||||||
if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings)) {
|
goto err;
|
||||||
fSettings.key_repeat_delay=200;
|
if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings))
|
||||||
fSettings.key_repeat_rate=250000;
|
goto err;
|
||||||
}
|
|
||||||
}
|
return;
|
||||||
}
|
err:
|
||||||
|
fSettings.key_repeat_delay = kb_default_key_repeat_delay;
|
||||||
|
fSettings.key_repeat_rate = kb_default_key_repeat_rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KeyboardSettings::~KeyboardSettings()
|
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)
|
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
|
||||||
{
|
{
|
||||||
fSettings.key_repeat_rate = rate;
|
fSettings.key_repeat_rate = rate;
|
||||||
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
** Distributed under the terms of the Haiku License.
|
||||||
**
|
**
|
||||||
** Author : Jérôme Duval
|
** Authors in chronological order:
|
||||||
** Original authors: [email protected]
|
** [email protected]
|
||||||
|
** Jérôme Duval
|
||||||
|
** Marcus Overhagen
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef KEYBOARD_SETTINGS_H_
|
#ifndef KEYBOARD_SETTINGS_H_
|
||||||
@@ -12,19 +14,22 @@
|
|||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <kb_mouse_settings.h>
|
#include <kb_mouse_settings.h>
|
||||||
|
|
||||||
class KeyboardSettings {
|
class KeyboardSettings
|
||||||
|
{
|
||||||
public :
|
public :
|
||||||
KeyboardSettings();
|
KeyboardSettings();
|
||||||
~KeyboardSettings();
|
~KeyboardSettings();
|
||||||
|
|
||||||
|
void SetKeyboardRepeatRate(int32 rate);
|
||||||
|
void SetKeyboardRepeatDelay(bigtime_t delay);
|
||||||
|
|
||||||
int32 KeyboardRepeatRate() const { return fSettings.key_repeat_rate; }
|
int32 KeyboardRepeatRate() const { return fSettings.key_repeat_rate; }
|
||||||
void SetKeyboardRepeatRate(int32 rate);
|
bigtime_t KeyboardRepeatDelay() const { return fSettings.key_repeat_delay; }
|
||||||
int32 KeyboardRepeatDelay() const { return fSettings.key_repeat_delay; }
|
|
||||||
void SetKeyboardRepeatDelay(int32 rate);
|
private:
|
||||||
|
void Save();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char kKeyboardSettingsFile[];
|
|
||||||
BPoint fCorner;
|
|
||||||
kb_settings fSettings;
|
kb_settings fSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user