diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2012-02-07 05:59:23 -0500 |
|---|---|---|
| committer | Tarmac <> | 2012-02-07 05:59:23 -0500 |
| commit | d3be0faa52e9f5498543df07c2e16fb60e5701e5 (patch) | |
| tree | a51b8ba31e86434c330eb2e4a408b27d1d1a2b7a | |
| parent | e861ff291fc02ae66a6ac6b7f9834542be185d28 (diff) | |
| parent | d15c04efe40fcf0f32744aec355f76c68412523a (diff) | |
. Fixes: . Approved by Sam Spilsbury, Marco Trevisan (TreviƱo).
(bzr r1908)
| -rw-r--r-- | plugins/unityshell/src/KeyboardUtil.h | 4 | ||||
| -rw-r--r-- | plugins/unityshell/src/UnityshellPrivate.cpp | 44 | ||||
| -rw-r--r-- | plugins/unityshell/src/UnityshellPrivate.h | 45 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.cpp | 21 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.h | 5 | ||||
| -rw-r--r-- | tests/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | tests/test_unityshell_private.cpp | 39 |
7 files changed, 144 insertions, 17 deletions
diff --git a/plugins/unityshell/src/KeyboardUtil.h b/plugins/unityshell/src/KeyboardUtil.h index 3ed1cef1e..f88c066f8 100644 --- a/plugins/unityshell/src/KeyboardUtil.h +++ b/plugins/unityshell/src/KeyboardUtil.h @@ -40,11 +40,11 @@ public: virtual ~KeyboardUtil(); guint GetKeycodeAboveKeySymbol(KeySym key_symbol); - + private: bool CompareOffsets (int current_x, int current_y, int best_x, int best_y); guint ConvertKeyToKeycode (XkbKeyPtr key); - + 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); diff --git a/plugins/unityshell/src/UnityshellPrivate.cpp b/plugins/unityshell/src/UnityshellPrivate.cpp new file mode 100644 index 000000000..029fb1c1d --- /dev/null +++ b/plugins/unityshell/src/UnityshellPrivate.cpp @@ -0,0 +1,44 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Andrea Azzarone <azzaronea@gmail.com> + */ + +#include "UnityshellPrivate.h" + +namespace unity +{ +namespace impl +{ + +std::string CreateActionString(std::string const& modifiers, + char shortcut, + ActionModifiers flag) +{ + std::string ret(modifiers); + + if (flag == ActionModifiers::USE_SHIFT) + ret += "<Shift>"; + else if (flag == ActionModifiers::USE_NUMPAD) + ret += "KP_"; + + ret += shortcut; + + return ret; +} + +} // namespace impl +} // namespace unity diff --git a/plugins/unityshell/src/UnityshellPrivate.h b/plugins/unityshell/src/UnityshellPrivate.h new file mode 100644 index 000000000..5ba395710 --- /dev/null +++ b/plugins/unityshell/src/UnityshellPrivate.h @@ -0,0 +1,45 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Andrea Azzarone <azzaronea@gmail.com> + */ + +#ifndef UNITYSHELL_UNITYSHELL_PRIVATE_H +#define UNITYSHELL_UNITYSHELL_PRIVATE_H + +#include <string> + +namespace unity +{ +namespace impl +{ + +enum class ActionModifiers +{ + NONE = 0, + + USE_NUMPAD, + USE_SHIFT +}; + +std::string CreateActionString(std::string const& modifiers, + char shortcut, + ActionModifiers flag = ActionModifiers::NONE); + +} // namespace impl +} // namespace unity + +#endif // UNITYSHELL_UNITYSHELL_PRIVATE_H diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 1124deb4e..a6fad33b4 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -362,7 +362,7 @@ UnityScreen::~UnityScreen() void UnityScreen::initAltTabNextWindow() { - KeyboardUtil key_util (screen->dpy()); + KeyboardUtil key_util(screen->dpy()); guint above_tab_keycode = key_util.GetKeycodeAboveKeySymbol (XStringToKeysym("Tab")); KeySym above_tab_keysym = XkbKeycodeToKeysym (screen->dpy(), above_tab_keycode, 0, 0); @@ -414,27 +414,22 @@ void UnityScreen::EnsureSuperKeybindings() for (auto shortcut : launcher_controller_->GetAllShortcuts()) { - CreateSuperNewAction(shortcut); - CreateSuperNewAction(shortcut, true); - CreateSuperNewAction(shortcut, false, true); + CreateSuperNewAction(shortcut, impl::ActionModifiers::NONE); + CreateSuperNewAction(shortcut, impl::ActionModifiers::USE_NUMPAD); + CreateSuperNewAction(shortcut, impl::ActionModifiers::USE_SHIFT); } for (auto shortcut : dash_controller_->GetAllShortcuts()) - CreateSuperNewAction(shortcut); + CreateSuperNewAction(shortcut, impl::ActionModifiers::NONE); } -void UnityScreen::CreateSuperNewAction(char shortcut, bool use_shift, bool use_numpad) +void UnityScreen::CreateSuperNewAction(char shortcut, impl::ActionModifiers flag) { CompActionPtr action(new CompAction()); + const std::string key(optionGetShowLauncher().keyToString()); CompAction::KeyBinding binding; - std::ostringstream sout; - if (use_shift) - sout << "<Shift><Super>" << shortcut; - else - sout << "<Super>" << ((use_numpad) ? "KP_" : "") << shortcut; - - binding.fromString(sout.str()); + binding.fromString(impl::CreateActionString(key, shortcut, flag)); action->setKey(binding); diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 98d70542b..337be3636 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -49,6 +49,7 @@ #include "DebugDBusInterface.h" #include "SwitcherController.h" #include "UBusWrapper.h" +#include "UnityshellPrivate.h" #ifndef USE_GLES #include "ScreenEffectFramebufferObject.h" #endif @@ -238,8 +239,8 @@ private: void SendExecuteCommand(); - void EnsureSuperKeybindings (); - void CreateSuperNewAction(char shortcut, bool use_shift=false, bool use_numpad=false); + void EnsureSuperKeybindings(); + void CreateSuperNewAction(char shortcut, impl::ActionModifiers flag); void EnableCancelAction(bool enabled, int modifiers = 0); static gboolean initPluginActions(gpointer data); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1759638f2..a849a1023 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -129,6 +129,7 @@ if (GTEST_FOUND AND test_introspection.cpp test_main_xless.cpp test_grabhandle.cpp + test_unityshell_private.cpp ${UNITY_SRC}/AbstractLauncherIcon.h ${UNITY_SRC}/AbstractShortcutHint.h ${UNITY_SRC}/Animator.cpp @@ -161,6 +162,8 @@ if (GTEST_FOUND AND ${UNITY_SRC}/TextureCache.h ${UNITY_SRC}/Timer.cpp ${UNITY_SRC}/Timer.h + ${UNITY_SRC}/UnityshellPrivate.cpp + ${UNITY_SRC}/UnityshellPrivate.h ${UNITY_SRC}/WindowManager.cpp ${UNITY_SRC}/WindowManager.h ${CMAKE_SOURCE_DIR}/plugins/unity-mt-grab-handles/src/unity-mt-grab-handle.cpp diff --git a/tests/test_unityshell_private.cpp b/tests/test_unityshell_private.cpp new file mode 100644 index 000000000..dba713feb --- /dev/null +++ b/tests/test_unityshell_private.cpp @@ -0,0 +1,39 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with this program. If not, see + * <http://www.gnu.org/licenses/> + * + * Authored by: Andrea Azzarone <azzaronea@gmail.com> + * + */ + +#include <gtest/gtest.h> + +#include "UnityshellPrivate.h" + +using namespace unity; + +TEST(TestUnityshellPrivate, TestCreateActionString) +{ + EXPECT_EQ(impl::CreateActionString("<Super>", 'a'), "<Super>a"); + EXPECT_EQ(impl::CreateActionString("<Super>", '1'), "<Super>1"); + + EXPECT_EQ(impl::CreateActionString("<Alt>", 'a'), "<Alt>a"); + EXPECT_EQ(impl::CreateActionString("<Alt>", '1'), "<Alt>1"); + + EXPECT_EQ(impl::CreateActionString("<Super>", '1', impl::ActionModifiers::USE_NUMPAD), "<Super>KP_1"); + + EXPECT_EQ(impl::CreateActionString("<Super>", '1', impl::ActionModifiers::USE_SHIFT), "<Super><Shift>1"); +} + |
