diff options
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/unityshell/src/GnomeKeyGrabber.cpp | 294 | ||||
| -rw-r--r-- | plugins/unityshell/src/GnomeKeyGrabber.h | 56 | ||||
| -rw-r--r-- | plugins/unityshell/src/GnomeKeyGrabberImpl.h | 80 | ||||
| -rw-r--r-- | plugins/unityshell/unityshell.xml.in | 4 |
4 files changed, 2 insertions, 432 deletions
diff --git a/plugins/unityshell/src/GnomeKeyGrabber.cpp b/plugins/unityshell/src/GnomeKeyGrabber.cpp deleted file mode 100644 index 64d1158f2..000000000 --- a/plugins/unityshell/src/GnomeKeyGrabber.cpp +++ /dev/null @@ -1,294 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright (C) 2013 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: William Hua <william.hua@canonical.com> - */ - -#include "GnomeKeyGrabberImpl.h" - -#include <NuxCore/Logger.h> - -namespace unity -{ -namespace grabber -{ -DECLARE_LOGGER(logger, "unity.grabber.gnome"); - -// Private implementation -namespace shell -{ -const std::string DBUS_NAME = "org.gnome.Shell"; -const std::string DBUS_INTERFACE = "org.gnome.Shell"; -const std::string DBUS_OBJECT_PATH = "/org/gnome/Shell"; -const std::string INTROSPECTION_XML = -R"(<node> - <interface name='org.gnome.Shell'> - <method name='GrabAccelerators'> - <arg type='a(su)' direction='in' name='accelerators'/> - <arg type='au' direction='out' name='actions'/> - </method> - <method name='GrabAccelerator'> - <arg type='s' direction='in' name='accelerator'/> - <arg type='u' direction='in' name='flags'/> - <arg type='u' direction='out' name='action'/> - </method> - <method name='UngrabAccelerator'> - <arg type='u' direction='in' name='action'/> - <arg type='b' direction='out' name='success'/> - </method> - <signal name='AcceleratorActivated'> - <arg type='u' name='action'/> - <arg type='u' name='device'/> - </signal> - </interface> -</node>)"; -} - -namespace testing -{ -const std::string DBUS_NAME = "com.canonical.Unity.Test.GnomeKeyGrabber"; -} - -bool GnomeKeyGrabber::Impl::BindingLess::operator() (const CompAction::KeyBinding& first, - const CompAction::KeyBinding& second) const -{ - int keycode1(first.keycode()); - int keycode2(second.keycode()); - - if (keycode1 == keycode2) - { - unsigned int modifiers1(first.modifiers()); - unsigned int modifiers2(second.modifiers()); - - return modifiers1 < modifiers2; - } - - return keycode1 < keycode2; -} - -GnomeKeyGrabber::Impl::Impl(CompScreen* screen, bool test_mode) - : test_mode_(test_mode) - , shell_server_(test_mode_ ? testing::DBUS_NAME : shell::DBUS_NAME) - , screen_(screen) - , current_action_id_(0) -{ - shell_server_.AddObjects(shell::INTROSPECTION_XML, shell::DBUS_OBJECT_PATH); - shell_object_ = shell_server_.GetObject(shell::DBUS_INTERFACE); - shell_object_->SetMethodsCallsHandler(sigc::mem_fun(this, &Impl::onShellMethodCall)); -} - -unsigned int GnomeKeyGrabber::Impl::addAction(const CompAction& action, - bool addressable) -{ - current_action_id_++; - actions_.push_back(action); - action_ids_.push_back(current_action_id_); - - if (addressable) - { - action_ids_by_action_[&action] = current_action_id_; - actions_by_action_id_[current_action_id_] = &action; - } - - CompAction& added(actions_.back()); - if (grabs_by_binding_[added.key()]++ == 0) - screen_->addAction(&added); - - return current_action_id_; -} - -bool GnomeKeyGrabber::Impl::removeAction(const CompAction& action) -{ - std::map<const CompAction*, unsigned int>::const_iterator i(action_ids_by_action_.find(&action)); - return i != action_ids_by_action_.end() && removeAction(i->second); -} - -bool GnomeKeyGrabber::Impl::removeAction(unsigned int action_id) -{ - std::vector<unsigned int>::iterator i(std::find(action_ids_.begin(), action_ids_.end(), action_id)); - - if (i != action_ids_.end()) - { - CompAction::Vector::iterator j(actions_.begin() + (i - action_ids_.begin())); - std::map<unsigned int, const CompAction*>::iterator k(actions_by_action_id_.find(action_id)); - - if (--grabs_by_binding_[j->key()] == 0) - screen_->removeAction(&*j); - - if (k != actions_by_action_id_.end()) - { - action_ids_by_action_.erase(k->second); - actions_by_action_id_.erase(k); - } - - action_ids_.erase(i); - actions_.erase(j); - return true; - } - - return false; -} - -GVariant* GnomeKeyGrabber::Impl::onShellMethodCall(const std::string& method, - GVariant* parameters) -{ - LOG_DEBUG(logger) << "Called method '" << method << "'"; - - if (method == "GrabAccelerators") - { - if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(a(su))"))) - { - GVariant* variant; - GVariantBuilder builder; - GVariantIter* iterator; - const gchar* accelerator; - guint flags; - - g_variant_builder_init(&builder, G_VARIANT_TYPE("au")); - g_variant_get(parameters, "(a(su))", &iterator); - - while (g_variant_iter_next(iterator, "(&su)", &accelerator, &flags)) - g_variant_builder_add(&builder, "u", grabAccelerator(accelerator, flags)); - - g_variant_iter_free(iterator); - variant = g_variant_builder_end(&builder); - return g_variant_new_tuple(&variant, 1); - } - else - LOG_WARN(logger) << "Expected arguments of type (a(su))"; - } - else if (method == "GrabAccelerator") - { - if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(su)"))) - { - GVariant* variant; - const gchar* accelerator; - guint flags; - - g_variant_get(parameters, "(&su)", &accelerator, &flags); - variant = g_variant_new_uint32(grabAccelerator(accelerator, flags)); - return g_variant_new_tuple(&variant, 1); - } - else - LOG_WARN(logger) << "Expected arguments of type (su)"; - } - else if (method == "UngrabAccelerator") - { - if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(u)"))) - { - GVariant* variant; - guint action; - - g_variant_get(parameters, "(u)", &action); - variant = g_variant_new_boolean(removeAction(action)); - return g_variant_new_tuple(&variant, 1); - } - else - LOG_WARN(logger) << "Expected arguments of type (u)"; - } - - return nullptr; -} - -unsigned int GnomeKeyGrabber::Impl::grabAccelerator(const char* accelerator, - unsigned int flags) -{ - CompAction action; - action.keyFromString(accelerator); - - if (!isActionPostponed(action)) - { - action.setState(CompAction::StateInitKey); - action.setInitiate(boost::bind(&GnomeKeyGrabber::Impl::actionInitiated, this, _1, _2, _3)); - } - else - { - action.setState(CompAction::StateInitKey | CompAction::StateTermKey); - action.setTerminate(boost::bind(&GnomeKeyGrabber::Impl::actionTerminated, this, _1, _2, _3)); - } - - return addAction(action, false); -} - -void GnomeKeyGrabber::Impl::activateAction(const CompAction* action, - unsigned int device) const -{ - ptrdiff_t i(action - &actions_.front()); - - if (0 <= i && i < static_cast<ptrdiff_t>(action_ids_.size())) - shell_object_->EmitSignal("AcceleratorActivated", g_variant_new("(uu)", action_ids_[i], device)); -} - -bool GnomeKeyGrabber::Impl::actionInitiated(CompAction* action, - CompAction::State state, - CompOption::Vector& options) const -{ - activateAction(action, 0); - return true; -} - -bool GnomeKeyGrabber::Impl::actionTerminated(CompAction* action, - CompAction::State state, - CompOption::Vector& options) const -{ - if (state & CompAction::StateTermTapped) - { - activateAction(action, 0); - return true; - } - - return false; -} - -bool GnomeKeyGrabber::Impl::isActionPostponed(const CompAction& action) const -{ - int keycode(action.key().keycode()); - return keycode == 0 || modHandler->keycodeToModifiers(keycode) != 0; -} - -// Public implementation - -GnomeKeyGrabber::GnomeKeyGrabber(CompScreen* screen) - : impl_(new Impl(screen)) -{ -} - -GnomeKeyGrabber::GnomeKeyGrabber(CompScreen* screen, const TestMode& dummy) - : impl_(new Impl(screen, true)) -{ -} - -GnomeKeyGrabber::~GnomeKeyGrabber() -{ -} - -CompAction::Vector& GnomeKeyGrabber::getActions() -{ - return impl_->actions_; -} - -void GnomeKeyGrabber::addAction(const CompAction& action) -{ - impl_->addAction(action); -} - -void GnomeKeyGrabber::removeAction(const CompAction& action) -{ - impl_->removeAction(action); -} - -} // namespace grabber -} // namespace unity diff --git a/plugins/unityshell/src/GnomeKeyGrabber.h b/plugins/unityshell/src/GnomeKeyGrabber.h deleted file mode 100644 index 1b71a442e..000000000 --- a/plugins/unityshell/src/GnomeKeyGrabber.h +++ /dev/null @@ -1,56 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* -* Copyright (C) 2013 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: William Hua <william.hua@canonical.com> -*/ - -#ifndef __GNOME_KEY_GRABBER_H__ -#define __GNOME_KEY_GRABBER_H__ - -#include <core/core.h> - -namespace unity -{ -namespace grabber -{ - -class GnomeKeyGrabber -{ -public: - - explicit GnomeKeyGrabber(CompScreen* screen); - virtual ~GnomeKeyGrabber(); - - CompAction::Vector& getActions(); - void addAction(const CompAction& action); - void removeAction(const CompAction& action); - - struct Impl; - -protected: - - struct TestMode {}; - GnomeKeyGrabber(CompScreen* screen, const TestMode& dummy); - -private: - - std::unique_ptr<Impl> impl_; -}; - -} // namespace grabber -} // namespace unity - -#endif // __GNOME_KEY_GRABBER_H__ diff --git a/plugins/unityshell/src/GnomeKeyGrabberImpl.h b/plugins/unityshell/src/GnomeKeyGrabberImpl.h deleted file mode 100644 index 4b597e89b..000000000 --- a/plugins/unityshell/src/GnomeKeyGrabberImpl.h +++ /dev/null @@ -1,80 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* -* Copyright (C) 2013 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: William Hua <william.hua@canonical.com> -*/ - -#ifndef __GNOME_KEY_GRABBER_IMPL_H__ -#define __GNOME_KEY_GRABBER_IMPL_H__ - -#include "GnomeKeyGrabber.h" - -#include <UnityCore/GLibDBusProxy.h> -#include <UnityCore/GLibDBusServer.h> - -namespace unity -{ -namespace grabber -{ - -struct GnomeKeyGrabber::Impl -{ - class BindingLess - { - public: - - bool operator()(const CompAction::KeyBinding& first, - const CompAction::KeyBinding& second) const; - }; - - bool test_mode_; - - glib::DBusServer shell_server_; - glib::DBusObject::Ptr shell_object_; - - CompScreen* screen_; - CompAction::Vector actions_; - std::vector<unsigned int> action_ids_; - unsigned int current_action_id_; - - std::map<const CompAction*, unsigned int> action_ids_by_action_; - std::map<unsigned int, const CompAction*> actions_by_action_id_; - std::map<CompAction::KeyBinding, unsigned int, BindingLess> grabs_by_binding_; - - explicit Impl(CompScreen* screen, bool test_mode = false); - - unsigned int addAction(const CompAction& action, bool addressable = true); - bool removeAction(const CompAction& action); - bool removeAction(unsigned int action_id); - - GVariant* onShellMethodCall(const std::string& method, GVariant* parameters); - unsigned int grabAccelerator(const char* accelerator, unsigned int flags); - void activateAction(const CompAction* action, unsigned int device) const; - - bool actionInitiated(CompAction* action, - CompAction::State state, - CompOption::Vector& options) const; - bool actionTerminated(CompAction* action, - CompAction::State state, - CompOption::Vector& options) const; - - bool isActionPostponed(const CompAction& action) const; -}; - -} // namespace grabber -} // namespace unity - -#endif // __GNOME_KEY_GRABBER_IMPL_H__ diff --git a/plugins/unityshell/unityshell.xml.in b/plugins/unityshell/unityshell.xml.in index a8c140071..190ac59b9 100644 --- a/plugins/unityshell/unityshell.xml.in +++ b/plugins/unityshell/unityshell.xml.in @@ -48,7 +48,7 @@ <_short>General</_short> <option name="show_menu_bar" type="key"> - <_short>Key to reveal the global menu bar</_short> + <_short>Key to show the menu bar while pressed</_short> <_long>Reveals the global menu bar while pressed.</_long> <default><Alt></default> </option> @@ -60,7 +60,7 @@ </option> <option name="show_hud" type="key"> - <_short>Key to show the HUD</_short> + <_short>Key to show the HUD when tapped</_short> <_long>A tap on this key summons the HUD.</_long> <default><Alt></default> </option> |
