diff options
| -rw-r--r-- | dash/DashView.cpp | 18 | ||||
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/KeyboardUtil.cpp (renamed from plugins/unityshell/src/KeyboardUtil.cpp) | 37 | ||||
| -rw-r--r-- | unity-shared/KeyboardUtil.h (renamed from plugins/unityshell/src/KeyboardUtil.h) | 15 |
4 files changed, 37 insertions, 34 deletions
diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 667bd9dff..da66419b5 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -30,6 +30,7 @@ #include <UnityCore/RadioOptionFilter.h> #include "unity-shared/DashStyle.h" +#include "unity-shared/KeyboardUtil.h" #include "unity-shared/UnitySettings.h" #include "unity-shared/UBusMessages.h" @@ -890,21 +891,8 @@ Area* DashView::FindKeyFocusArea(unsigned int key_symbol, } } - bool valid_search_key = false; - - if (direction == KEY_NAV_NONE) - { - /* Excluding meta chars, see keysymdef.h for reference */ - if (x11_key_code < XK_Select || x11_key_code > XK_Hyper_R) - { - if (x11_key_code == XK_Delete || x11_key_code == XK_BackSpace) - valid_search_key = true; - else - valid_search_key = g_unichar_isprint(x11_key_code); - } - } - - if (valid_search_key || search_bar_->im_preedit) + if ((direction == KEY_NAV_NONE && ui::KeyboardUtil::IsPrintableKeySymbol(x11_key_code)) || + search_bar_->im_preedit) { // then send the event to the search entry return search_bar_->text_entry(); diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 608d312d5..4e87f8bb6 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -34,6 +34,7 @@ set (UNITY_SHARED_SOURCES BackgroundEffectHelper.cpp DashStyle.cpp FontSettings.cpp + KeyboardUtil.cpp IMTextEntry.cpp IconLoader.cpp IconRenderer.cpp diff --git a/plugins/unityshell/src/KeyboardUtil.cpp b/unity-shared/KeyboardUtil.cpp index 50dc200a7..b4e824e77 100644 --- a/plugins/unityshell/src/KeyboardUtil.cpp +++ b/unity-shared/KeyboardUtil.cpp @@ -18,7 +18,6 @@ */ #include <string.h> - #include <stdio.h> #include <cmath> @@ -31,7 +30,7 @@ KeyboardUtil::KeyboardUtil(Display *display) : display_(display) { unsigned int fetch_mask = XkbGBN_KeyNamesMask | XkbGBN_ClientSymbolsMask | XkbGBN_GeometryMask; - keyboard_ = XkbGetKeyboard (display, fetch_mask, XkbUseCoreKbd); + keyboard_ = XkbGetKeyboard (display, fetch_mask, XkbUseCoreKbd); } KeyboardUtil::~KeyboardUtil() @@ -39,7 +38,7 @@ KeyboardUtil::~KeyboardUtil() XkbFreeKeyboard (keyboard_, 0, True); } -bool KeyboardUtil::FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds) +bool KeyboardUtil::FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds) const { // seems that Xkb does not give null terminated strings... was painful int name_length = XkbKeyNameLength; @@ -73,7 +72,7 @@ bool KeyboardUtil::FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& re return false; } -bool KeyboardUtil::CompareOffsets (int current_x, int current_y, int best_x, int best_y) +bool KeyboardUtil::CompareOffsets(int current_x, int current_y, int best_x, int best_y) const { // never EVER prefer something higher on the keyboard than what we have if (current_y > best_y) @@ -85,7 +84,7 @@ bool KeyboardUtil::CompareOffsets (int current_x, int current_y, int best_x, int return false; } -guint KeyboardUtil::ConvertKeyToKeycode (XkbKeyPtr key) +guint KeyboardUtil::ConvertKeyToKeycode(XkbKeyPtr key) const { int min_code = keyboard_->min_key_code; int max_code = keyboard_->max_key_code; @@ -98,7 +97,7 @@ guint KeyboardUtil::ConvertKeyToKeycode (XkbKeyPtr key) return 0; } -XkbBoundsRec KeyboardUtil::GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo) +XkbBoundsRec KeyboardUtil::GetAbsoluteKeyBounds(XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo) const { XkbShapePtr shape = XkbKeyShape(geo, key); @@ -117,7 +116,7 @@ XkbBoundsRec KeyboardUtil::GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, X y_offset += local_shape->bounds.y2 - local_shape->bounds.y1; else x_offset += local_shape->bounds.x2 - local_shape->bounds.x1; - + i++; } @@ -129,7 +128,7 @@ XkbBoundsRec KeyboardUtil::GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, X return result; } -bool KeyboardUtil::FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section_index, XkbBoundsRec const& target_bounds, guint &keycode) +bool KeyboardUtil::FindKeyInSectionAboveBounds(XkbGeometryPtr geo, int section_index, XkbBoundsRec const& target_bounds, guint &keycode) const { XkbKeyPtr best = NULL; int best_x_offset = G_MAXINT; @@ -155,7 +154,7 @@ bool KeyboardUtil::FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section_ int center = (bounds.x1 + bounds.x2) / 2; if (center < target_bounds.x1 || center > target_bounds.x2) continue; - + // make sure the key is actually above our target. int current_y_offset = target_bounds.y1 - bounds.y2; if (current_y_offset < 0) @@ -181,7 +180,7 @@ bool KeyboardUtil::FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section_ return false; } -guint KeyboardUtil::GetKeycodeAboveKeySymbol(KeySym key_symbol) +guint KeyboardUtil::GetKeycodeAboveKeySymbol(KeySym key_symbol) const { guint result = 0; @@ -208,9 +207,25 @@ guint KeyboardUtil::GetKeycodeAboveKeySymbol(KeySym key_symbol) if (found_key) result = maybe; } - + return result; } +bool KeyboardUtil::IsPrintableKeySymbol(KeySym key_symbol) +{ + bool printable_key = false; + + /* Excluding meta chars, see keysymdef.h for reference */ + if (key_symbol < XK_Select || key_symbol > XK_Hyper_R) + { + if (key_symbol == XK_Delete || key_symbol == XK_BackSpace) + printable_key = true; + else + printable_key = g_unichar_isprint(key_symbol); + } + + return printable_key; +} + } } \ No newline at end of file diff --git a/plugins/unityshell/src/KeyboardUtil.h b/unity-shared/KeyboardUtil.h index f88c066f8..224402925 100644 --- a/plugins/unityshell/src/KeyboardUtil.h +++ b/unity-shared/KeyboardUtil.h @@ -33,22 +33,21 @@ namespace ui class KeyboardUtil { - public: - KeyboardUtil(Display *display); virtual ~KeyboardUtil(); - guint GetKeycodeAboveKeySymbol(KeySym key_symbol); + guint GetKeycodeAboveKeySymbol(KeySym key_symbol) const; + static bool IsPrintableKeySymbol(KeySym key_symbol); private: - bool CompareOffsets (int current_x, int current_y, int best_x, int best_y); - guint ConvertKeyToKeycode (XkbKeyPtr key); + bool CompareOffsets (int current_x, int current_y, int best_x, int best_y) const; + guint ConvertKeyToKeycode (XkbKeyPtr key) const; - bool FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds); - bool FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section, XkbBoundsRec const& target_bounds, guint &keycode); + bool FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds) const; + bool FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section, XkbBoundsRec const& target_bounds, guint &keycode) const; - XkbBoundsRec GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo); + XkbBoundsRec GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo) const; XkbDescPtr keyboard_; Display *display_; |
