Modified bin/keymap's -h option to write a variable to the generated header
indicating the name of the keymap. Correspondingly, modified input_server to use the aforementioned variable in order to write the name attribute to ~/config/Key_map. This allows Keymap prefs to correctly recognize the name of the default keymap on a fresh build. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24951 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -773,13 +773,22 @@ Keymap::Save(entry_ref &ref)
|
|||||||
into the input_server, for example.
|
into the input_server, for example.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Keymap::SaveAsHeader(entry_ref &ref)
|
Keymap::SaveAsHeader(entry_ref &ref, const char *mapName)
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
status_t err = path.SetTo(&ref);
|
status_t err = path.SetTo(&ref);
|
||||||
if (err < B_OK)
|
if (err < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
BString name = mapName;
|
||||||
|
int slashidx = name.FindLast('/');
|
||||||
|
if (slashidx > 0) {
|
||||||
|
// prune off path
|
||||||
|
name.Remove(0, slashidx + 1);
|
||||||
|
}
|
||||||
|
// prune ".keymap"
|
||||||
|
name.Remove(name.FindLast('.'), 7);
|
||||||
|
|
||||||
FILE* file = fopen(path.Path(), "w");
|
FILE* file = fopen(path.Path(), "w");
|
||||||
|
|
||||||
fprintf(file, "/*\n"
|
fprintf(file, "/*\n"
|
||||||
@@ -787,6 +796,7 @@ Keymap::SaveAsHeader(entry_ref &ref)
|
|||||||
" * This file is generated automatically. Don't edit!\n"
|
" * This file is generated automatically. Don't edit!\n"
|
||||||
" */\n\n");
|
" */\n\n");
|
||||||
fprintf(file, "#include <InterfaceDefs.h>\n\n");
|
fprintf(file, "#include <InterfaceDefs.h>\n\n");
|
||||||
|
fprintf(file, "const char *kSystemKeymapName = \"%s\";\n\n", name.String());
|
||||||
fprintf(file, "const key_map kSystemKeymap = {\n");
|
fprintf(file, "const key_map kSystemKeymap = {\n");
|
||||||
fprintf(file, "\tversion:%ld,\n", fKeys.version);
|
fprintf(file, "\tversion:%ld,\n", fKeys.version);
|
||||||
fprintf(file, "\tcaps_key:0x%lx,\n", fKeys.caps_key);
|
fprintf(file, "\tcaps_key:0x%lx,\n", fKeys.caps_key);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Keymap {
|
|||||||
status_t LoadSource(FILE *f);
|
status_t LoadSource(FILE *f);
|
||||||
status_t LoadSourceFromRef(entry_ref &ref);
|
status_t LoadSourceFromRef(entry_ref &ref);
|
||||||
void SaveAsCurrent();
|
void SaveAsCurrent();
|
||||||
void SaveAsHeader(entry_ref &ref);
|
void SaveAsHeader(entry_ref &ref, const char *mapname);
|
||||||
status_t Use();
|
status_t Use();
|
||||||
void Dump();
|
void Dump();
|
||||||
bool IsModifierKey(uint32 keyCode);
|
bool IsModifierKey(uint32 keyCode);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ main(int argc, char **argv)
|
|||||||
} else if (operation == 'h') {
|
} else if (operation == 'h') {
|
||||||
Keymap keymap;
|
Keymap keymap;
|
||||||
load_keymap_source(keymap, argv[i]);
|
load_keymap_source(keymap, argv[i]);
|
||||||
keymap.SaveAsHeader(outputRef);
|
keymap.SaveAsHeader(outputRef, argv[i]);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (operation == 'b') {
|
} else if (operation == 'b') {
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
|
|||||||
@@ -309,12 +309,12 @@ InputServer::_LoadSystemKeymap()
|
|||||||
memcpy(fChars, kSystemKeyChars, fCharsSize);
|
memcpy(fChars, kSystemKeyChars, fCharsSize);
|
||||||
|
|
||||||
// TODO: why are we doing this?
|
// TODO: why are we doing this?
|
||||||
return _SaveKeymap();
|
return _SaveKeymap(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
InputServer::_SaveKeymap()
|
InputServer::_SaveKeymap(bool isDefault)
|
||||||
{
|
{
|
||||||
// we save this keymap to file
|
// we save this keymap to file
|
||||||
BPath path;
|
BPath path;
|
||||||
@@ -349,6 +349,12 @@ InputServer::_SaveKeymap()
|
|||||||
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
|
if ((err = file.Write(fChars, fCharsSize)) < (ssize_t)fCharsSize)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
// don't bother reporting an error if this fails, since this isn't fatal
|
||||||
|
// the keymap will still be functional, and will just be identified as (Current) in prefs instead of its
|
||||||
|
// actual name
|
||||||
|
if (isDefault)
|
||||||
|
file.WriteAttr("keymap:name", B_STRING_TYPE, 0, kSystemKeymapName, strlen(kSystemKeymapName));
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ class InputServer : public BApplication {
|
|||||||
|
|
||||||
status_t _LoadKeymap();
|
status_t _LoadKeymap();
|
||||||
status_t _LoadSystemKeymap();
|
status_t _LoadSystemKeymap();
|
||||||
status_t _SaveKeymap();
|
status_t _SaveKeymap(bool isDefault = false);
|
||||||
void _InitKeyboardMouseStates();
|
void _InitKeyboardMouseStates();
|
||||||
|
|
||||||
status_t _StartEventLoop();
|
status_t _StartEventLoop();
|
||||||
|
|||||||
Reference in New Issue
Block a user