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
10 #include <FindDirectory.h>
14 #include "KeyboardSettings.h"
16 // Keyboard setting file layout is like this:
18 // struct kb_settings; // managed by input server
19 // BPoint corner; // used by pref app
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
;
38 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
40 status
= path
.Append(kb_settings_file
);
42 status
= file
.SetTo(path
.Path(), B_READ_ONLY
);
44 if (file
.ReadAt(sizeof(kb_settings
), &fCorner
, sizeof(fCorner
)) != sizeof(fCorner
)) {
54 KeyboardSettings::~KeyboardSettings()
59 if (find_directory(B_USER_SETTINGS_DIRECTORY
, &path
) < B_OK
)
62 if (path
.Append(kb_settings_file
) < B_OK
)
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
)
69 file
.WriteAt(sizeof(kb_settings
), &fCorner
, sizeof(fCorner
));
74 KeyboardSettings::SetWindowCorner(BPoint corner
)
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
;
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
;
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
);
107 KeyboardSettings::Revert()
109 SetKeyboardRepeatDelay(fOriginalSettings
.key_repeat_delay
);
110 SetKeyboardRepeatRate(fOriginalSettings
.key_repeat_rate
);
115 KeyboardSettings::Defaults()
117 SetKeyboardRepeatDelay(kb_default_key_repeat_delay
);
118 SetKeyboardRepeatRate(kb_default_key_repeat_rate
);
123 KeyboardSettings::IsDefaultable()
125 return fSettings
.key_repeat_delay
!= kb_default_key_repeat_delay
126 || fSettings
.key_repeat_rate
!= kb_default_key_repeat_rate
;