From b9d9c282fd135d57db47a12c0a44fe0d6d5a6beb Mon Sep 17 00:00:00 2001 From: Simon South Date: Sat, 24 Aug 2019 21:26:23 -0400 Subject: [PATCH] input_server: Notify apps of new key map Define a new message, B_KEY_MAP_LOADED, that is broadcast to applications by the Input Server each time a key map is loaded. This allows apps that cache key-map data to know when their copy has become stale. Change InputServer::HandleGetSetKeyMap() so it returns an error in the event loading even the system (fallback) key map fails. Change-Id: Icc6c884f695ca59c687d83c680bb2fb467dd90cc Reviewed-on: https://review.haiku-os.org/c/haiku/+/1741 Reviewed-by: waddlesplash --- headers/os/app/AppDefs.h | 1 + src/servers/input/InputServer.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/headers/os/app/AppDefs.h b/headers/os/app/AppDefs.h index 0533c327cb..d8624b7e93 100644 --- a/headers/os/app/AppDefs.h +++ b/headers/os/app/AppDefs.h @@ -38,6 +38,7 @@ enum { B_KEY_UP = '_KYU', B_UNMAPPED_KEY_DOWN = '_UKD', B_UNMAPPED_KEY_UP = '_UKU', + B_KEY_MAP_LOADED = '_KML', B_LAYOUT_WINDOW = '_LAY', B_MODIFIERS_CHANGED = '_MCH', B_MINIMIZE = '_WMN', diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 0dc4ab46c6..b994ef485c 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -932,21 +932,33 @@ InputServer::HandleGetSetKeyMap(BMessage* message, BMessage* reply) { CALLED(); + status_t status; if (message->what == IS_GET_KEY_MAP) { - status_t status = reply->AddData("keymap", B_ANY_TYPE, &fKeys, sizeof(fKeys)); + status = reply->AddData("keymap", B_ANY_TYPE, &fKeys, sizeof(fKeys)); if (status == B_OK) status = reply->AddData("key_buffer", B_ANY_TYPE, fChars, fCharsSize); return status; } - if (_LoadKeymap() != B_OK) - _LoadSystemKeymap(); + status = _LoadKeymap(); + if (status != B_OK) { + status = _LoadSystemKeymap(); + if (status != B_OK) + return status; + } BMessage msg(IS_CONTROL_DEVICES); msg.AddInt32("type", B_KEYBOARD_DEVICE); msg.AddInt32("code", B_KEY_MAP_CHANGED); - return fAddOnManager->PostMessage(&msg); + status = fAddOnManager->PostMessage(&msg); + + if (status == B_OK) { + BMessage appMsg(B_KEY_MAP_LOADED); + be_roster->Broadcast(&appMsg); + } + + return status; }