summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2014-02-12 05:04:39 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2014-02-12 05:04:39 +0100
commit2bec9c876fc31b90b09af67f8d078daf11bb3497 (patch)
tree3fc8df431816471771126ab082fce8ce8ff6e5ae /unity-shared
parent76c31bb9542c7718db86c919446c9d4de2edeaf5 (diff)
KeyGrabber: add abstract class and implement it in GnomeKeyGrabber
(bzr r3652.3.1)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/GnomeKeyGrabber.cpp51
-rw-r--r--unity-shared/GnomeKeyGrabber.h23
-rw-r--r--unity-shared/GnomeKeyGrabberImpl.h14
-rw-r--r--unity-shared/KeyGrabber.h43
4 files changed, 85 insertions, 46 deletions
diff --git a/unity-shared/GnomeKeyGrabber.cpp b/unity-shared/GnomeKeyGrabber.cpp
index 4333b3d06..2d8cb350d 100644
--- a/unity-shared/GnomeKeyGrabber.cpp
+++ b/unity-shared/GnomeKeyGrabber.cpp
@@ -23,7 +23,9 @@
namespace unity
{
-DECLARE_LOGGER(logger, "unity.gnome");
+namespace key
+{
+DECLARE_LOGGER(logger, "unity.key.gnome.grabber");
// Private implementation
namespace shell
@@ -60,9 +62,8 @@ namespace testing
std::string const DBUS_NAME = "com.canonical.Unity.Test.GnomeKeyGrabber";
}
-GnomeKeyGrabber::Impl::Impl(CompScreen* screen, bool test_mode)
- : test_mode_(test_mode)
- , shell_server_(test_mode_ ? testing::DBUS_NAME : shell::DBUS_NAME)
+GnomeGrabber::Impl::Impl(bool test_mode)
+ : shell_server_(test_mode ? testing::DBUS_NAME : shell::DBUS_NAME)
, screen_(screen)
, current_action_id_(0)
{
@@ -71,7 +72,7 @@ GnomeKeyGrabber::Impl::Impl(CompScreen* screen, bool test_mode)
shell_object_->SetMethodsCallsHandler(sigc::mem_fun(this, &Impl::onShellMethodCall));
}
-GnomeKeyGrabber::Impl::~Impl()
+GnomeGrabber::Impl::~Impl()
{
if (screen_)
{
@@ -80,7 +81,7 @@ GnomeKeyGrabber::Impl::~Impl()
}
}
-unsigned int GnomeKeyGrabber::Impl::addAction(CompAction const& action, bool addressable)
+unsigned int GnomeGrabber::Impl::addAction(CompAction const& action, bool addressable)
{
++current_action_id_;
actions_.push_back(action);
@@ -98,13 +99,13 @@ unsigned int GnomeKeyGrabber::Impl::addAction(CompAction const& action, bool add
return current_action_id_;
}
-bool GnomeKeyGrabber::Impl::removeAction(CompAction const& action)
+bool GnomeGrabber::Impl::removeAction(CompAction const& action)
{
auto 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)
+bool GnomeGrabber::Impl::removeAction(unsigned int action_id)
{
auto i = std::find(action_ids_.begin(), action_ids_.end(), action_id);
@@ -130,7 +131,7 @@ bool GnomeKeyGrabber::Impl::removeAction(unsigned int action_id)
return false;
}
-GVariant* GnomeKeyGrabber::Impl::onShellMethodCall(std::string const& method, GVariant* parameters)
+GVariant* GnomeGrabber::Impl::onShellMethodCall(std::string const& method, GVariant* parameters)
{
LOG_DEBUG(logger) << "Called method '" << method << "'";
@@ -190,7 +191,7 @@ GVariant* GnomeKeyGrabber::Impl::onShellMethodCall(std::string const& method, GV
return nullptr;
}
-unsigned int GnomeKeyGrabber::Impl::grabAccelerator(char const* accelerator, unsigned int flags)
+unsigned int GnomeGrabber::Impl::grabAccelerator(char const* accelerator, unsigned int flags)
{
CompAction action;
action.keyFromString(accelerator);
@@ -220,7 +221,7 @@ unsigned int GnomeKeyGrabber::Impl::grabAccelerator(char const* accelerator, uns
return addAction(action, false);
}
-void GnomeKeyGrabber::Impl::activateAction(CompAction const* action, unsigned int device) const
+void GnomeGrabber::Impl::activateAction(CompAction const* action, unsigned int device) const
{
ptrdiff_t i = action - &actions_.front();
@@ -228,7 +229,7 @@ void GnomeKeyGrabber::Impl::activateAction(CompAction const* action, unsigned in
shell_object_->EmitSignal("AcceleratorActivated", g_variant_new("(uu)", action_ids_[i], device));
}
-bool GnomeKeyGrabber::Impl::isActionPostponed(CompAction const& action) const
+bool GnomeGrabber::Impl::isActionPostponed(CompAction const& action) const
{
int keycode = action.key().keycode();
return keycode == 0 || modHandler->keycodeToModifiers(keycode) != 0;
@@ -236,33 +237,31 @@ bool GnomeKeyGrabber::Impl::isActionPostponed(CompAction const& action) const
// Public implementation
-GnomeKeyGrabber::GnomeKeyGrabber(CompScreen* screen)
- : impl_(new Impl(screen))
-{
-}
+GnomeGrabber::GnomeGrabber()
+ : impl_(new Impl())
+{}
-GnomeKeyGrabber::GnomeKeyGrabber(CompScreen* screen, TestMode const& dummy)
- : impl_(new Impl(screen, true))
-{
-}
+GnomeGrabber::GnomeGrabber(TestMode const& dummy)
+ : impl_(new Impl(true))
+{}
-GnomeKeyGrabber::~GnomeKeyGrabber()
-{
-}
+GnomeGrabber::~GnomeGrabber()
+{}
-CompAction::Vector& GnomeKeyGrabber::getActions()
+CompAction::Vector& GnomeGrabber::getActions()
{
return impl_->actions_;
}
-void GnomeKeyGrabber::addAction(CompAction const& action)
+void GnomeGrabber::addAction(CompAction const& action)
{
impl_->addAction(action);
}
-void GnomeKeyGrabber::removeAction(CompAction const& action)
+void GnomeGrabber::removeAction(CompAction const& action)
{
impl_->removeAction(action);
}
+} // namespace key
} // namespace unity
diff --git a/unity-shared/GnomeKeyGrabber.h b/unity-shared/GnomeKeyGrabber.h
index 5b4ec6f62..d90cc83c8 100644
--- a/unity-shared/GnomeKeyGrabber.h
+++ b/unity-shared/GnomeKeyGrabber.h
@@ -20,35 +20,32 @@
#ifndef __GNOME_KEY_GRABBER_H__
#define __GNOME_KEY_GRABBER_H__
-#include <core/core.h>
+#include "KeyGrabber.h"
namespace unity
{
-
-class GnomeKeyGrabber
+namespace key
+{
+class GnomeGrabber : public Grabber
{
public:
-
- typedef std::shared_ptr<GnomeKeyGrabber> Ptr;
-
- explicit GnomeKeyGrabber(CompScreen* screen);
- virtual ~GnomeKeyGrabber();
+ GnomeGrabber();
+ virtual ~GnomeGrabber();
CompAction::Vector& getActions();
- void addAction(CompAction const& action);
- void removeAction(CompAction const& action);
+ void addAction(CompAction const&);
+ void removeAction(CompAction const&);
protected:
-
struct TestMode {};
- GnomeKeyGrabber(CompScreen* screen, TestMode const& dummy);
+ GnomeGrabber(TestMode const& dummy);
private:
-
struct Impl;
std::unique_ptr<Impl> impl_;
};
+} // namespace key
} // namespace unity
#endif // __GNOME_KEY_GRABBER_H__
diff --git a/unity-shared/GnomeKeyGrabberImpl.h b/unity-shared/GnomeKeyGrabberImpl.h
index 3367ce9b9..6c65c91fe 100644
--- a/unity-shared/GnomeKeyGrabberImpl.h
+++ b/unity-shared/GnomeKeyGrabberImpl.h
@@ -22,17 +22,19 @@
#include "GnomeKeyGrabber.h"
+#include <unordered_map>
#include <UnityCore/GLibDBusProxy.h>
#include <UnityCore/GLibDBusServer.h>
-#include <unordered_map>
-
namespace unity
{
+namespace key
+{
-struct GnomeKeyGrabber::Impl
+struct GnomeGrabber::Impl
{
- bool test_mode_;
+ Impl(bool test_mode = false);
+ ~Impl();
glib::DBusServer shell_server_;
glib::DBusObject::Ptr shell_object_;
@@ -45,9 +47,6 @@ struct GnomeKeyGrabber::Impl
std::unordered_map<CompAction const*, unsigned int> action_ids_by_action_;
std::unordered_map<unsigned int, CompAction const*> actions_by_action_id_;
- explicit Impl(CompScreen* screen, bool test_mode = false);
- ~Impl();
-
unsigned int addAction(CompAction const& action, bool addressable = true);
bool removeAction(CompAction const& action);
bool removeAction(unsigned int action_id);
@@ -59,6 +58,7 @@ struct GnomeKeyGrabber::Impl
bool isActionPostponed(CompAction const& action) const;
};
+} // namespace key
} // namespace unity
#endif // __GNOME_KEY_GRABBER_IMPL_H__
diff --git a/unity-shared/KeyGrabber.h b/unity-shared/KeyGrabber.h
new file mode 100644
index 000000000..86ba6e16c
--- /dev/null
+++ b/unity-shared/KeyGrabber.h
@@ -0,0 +1,43 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+* Copyright (C) 2014 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: Marco Trevisan <marco.trevisan@canonical.com>
+*/
+
+#ifndef __UNITY_KEY_GRABBER__
+#define __UNITY_KEY_GRABBER__
+
+#include <core/core.h>
+
+namespace unity
+{
+namespace key
+{
+class Grabber
+{
+public:
+ typedef std::shared_ptr<Grabber> Ptr;
+ virtual ~Grabber() = default;
+
+ virtual CompAction::Vector& getActions() = 0;
+ virtual void addAction(CompAction const&) = 0;
+ virtual void removeAction(CompAction const&) = 0;
+};
+
+} // namespace key
+} // namespace unity
+
+#endif // __UNITY_KEY_GRABBER__