usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / preferences / keyboard / KeyboardSettings.cpp
blob4846203aea3c271a540e9c88b75049e6b967827a
1 /*
2 * Copyright 2004-2006, the Haiku project. All rights reserved.
3 * Distributed under the terms of the Haiku License.
5 * Authors in chronological order:
6 * mccall@digitalparadise.co.uk
7 * Jérôme Duval
8 * Marcus Overhagen
9 */
10 #include <FindDirectory.h>
11 #include <File.h>
12 #include <Path.h>
13 #include <stdio.h>
14 #include "KeyboardSettings.h"
16 // Keyboard setting file layout is like this:
17 // struct {
18 // struct kb_settings; // managed by input server
19 // BPoint corner; // used by pref app
20 // }
22 KeyboardSettings::KeyboardSettings()
24 if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK)
25 fSettings.key_repeat_rate = kb_default_key_repeat_rate;
27 if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK)
28 fSettings.key_repeat_delay = kb_default_key_repeat_delay;
30 fOriginalSettings = fSettings;
32 BPath path;
33 BFile file;
35 fCorner.x = 150;
36 fCorner.y = 100;
38 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
39 if (status == B_OK) {
40 status = path.Append(kb_settings_file);
41 if (status == B_OK) {
42 status = file.SetTo(path.Path(), B_READ_ONLY);
43 if (status == B_OK) {
44 if (file.ReadAt(sizeof(kb_settings), &fCorner, sizeof(fCorner)) != sizeof(fCorner)) {
45 fCorner.x = 150;
46 fCorner.y = 100;
54 KeyboardSettings::~KeyboardSettings()
56 BPath path;
57 BFile file;
59 if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
60 return;
62 if (path.Append(kb_settings_file) < B_OK)
63 return;
65 // be careful: don't create the file if it doesn't already exist
66 if (file.SetTo(path.Path(), B_WRITE_ONLY) < B_OK)
67 return;
69 file.WriteAt(sizeof(kb_settings), &fCorner, sizeof(fCorner));
73 void
74 KeyboardSettings::SetWindowCorner(BPoint corner)
76 fCorner = corner;
80 void
81 KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
83 if (set_key_repeat_rate(rate) != B_OK)
84 fprintf(stderr, "error while set_key_repeat_rate!\n");
85 fSettings.key_repeat_rate = rate;
89 void
90 KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay)
92 if (set_key_repeat_delay(delay) != B_OK)
93 fprintf(stderr, "error while set_key_repeat_delay!\n");
94 fSettings.key_repeat_delay = delay;
98 void
99 KeyboardSettings::Dump()
101 printf("repeat rate: %" B_PRId32 "\n", fSettings.key_repeat_rate);
102 printf("repeat delay: %" B_PRId64 "\n", fSettings.key_repeat_delay);
106 void
107 KeyboardSettings::Revert()
109 SetKeyboardRepeatDelay(fOriginalSettings.key_repeat_delay);
110 SetKeyboardRepeatRate(fOriginalSettings.key_repeat_rate);
114 void
115 KeyboardSettings::Defaults()
117 SetKeyboardRepeatDelay(kb_default_key_repeat_delay);
118 SetKeyboardRepeatRate(kb_default_key_repeat_rate);
122 bool
123 KeyboardSettings::IsDefaultable()
125 return fSettings.key_repeat_delay != kb_default_key_repeat_delay
126 || fSettings.key_repeat_rate != kb_default_key_repeat_rate;