Home | History | Annotate | Download | only in input
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _LIBINPUT_KEYBOARD_H
     18 #define _LIBINPUT_KEYBOARD_H
     19 
     20 #include <input/Input.h>
     21 #include <input/InputDevice.h>
     22 #include <input/InputEventLabels.h>
     23 #include <utils/Errors.h>
     24 #include <utils/String8.h>
     25 #include <utils/PropertyMap.h>
     26 
     27 namespace android {
     28 
     29 enum {
     30     /* Device id of the built in keyboard. */
     31     DEVICE_ID_BUILT_IN_KEYBOARD = 0,
     32 
     33     /* Device id of a generic virtual keyboard with a full layout that can be used
     34      * to synthesize key events. */
     35     DEVICE_ID_VIRTUAL_KEYBOARD = -1,
     36 };
     37 
     38 class KeyLayoutMap;
     39 class KeyCharacterMap;
     40 
     41 /**
     42  * Loads the key layout map and key character map for a keyboard device.
     43  */
     44 class KeyMap {
     45 public:
     46     String8 keyLayoutFile;
     47     sp<KeyLayoutMap> keyLayoutMap;
     48 
     49     String8 keyCharacterMapFile;
     50     sp<KeyCharacterMap> keyCharacterMap;
     51 
     52     KeyMap();
     53     ~KeyMap();
     54 
     55     status_t load(const InputDeviceIdentifier& deviceIdenfier,
     56             const PropertyMap* deviceConfiguration);
     57 
     58     inline bool haveKeyLayout() const {
     59         return !keyLayoutFile.isEmpty();
     60     }
     61 
     62     inline bool haveKeyCharacterMap() const {
     63         return !keyCharacterMapFile.isEmpty();
     64     }
     65 
     66     inline bool isComplete() const {
     67         return haveKeyLayout() && haveKeyCharacterMap();
     68     }
     69 
     70 private:
     71     bool probeKeyMap(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
     72     status_t loadKeyLayout(const InputDeviceIdentifier& deviceIdentifier, const String8& name);
     73     status_t loadKeyCharacterMap(const InputDeviceIdentifier& deviceIdentifier,
     74             const String8& name);
     75     String8 getPath(const InputDeviceIdentifier& deviceIdentifier,
     76             const String8& name, InputDeviceConfigurationFileType type);
     77 };
     78 
     79 /**
     80  * Returns true if the keyboard is eligible for use as a built-in keyboard.
     81  */
     82 extern bool isEligibleBuiltInKeyboard(const InputDeviceIdentifier& deviceIdentifier,
     83         const PropertyMap* deviceConfiguration, const KeyMap* keyMap);
     84 
     85 /**
     86  * Updates a meta state field when a key is pressed or released.
     87  */
     88 extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
     89 
     90 /**
     91  * Returns true if a key is a meta key like ALT or CAPS_LOCK.
     92  */
     93 extern bool isMetaKey(int32_t keyCode);
     94 
     95 } // namespace android
     96 
     97 #endif // _LIBINPUT_KEYBOARD_H
     98