diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2012-05-17 13:52:32 +0200 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2012-05-17 13:52:32 +0200 |
| commit | c16735baf6f6f9fcdfd6466fa4d5fbe144f9c59b (patch) | |
| tree | a13a7f0a6f49b0221080f9c7c0b38210d4227de4 /shortcuts | |
| parent | a8bd13f25884d6362c4a693fcb6203e3f6378d58 (diff) | |
| parent | bbd1b06505d6f348bcc8e5a4c667b021685858ec (diff) | |
Merge trunk.
(bzr r2348.1.6)
Diffstat (limited to 'shortcuts')
| -rw-r--r-- | shortcuts/AbstractShortcutHint.h | 104 | ||||
| -rw-r--r-- | shortcuts/CMakeLists.txt | 51 | ||||
| -rw-r--r-- | shortcuts/MockShortcutHint.h | 73 | ||||
| -rw-r--r-- | shortcuts/ShortcutController.cpp | 252 | ||||
| -rw-r--r-- | shortcuts/ShortcutController.h | 99 | ||||
| -rw-r--r-- | shortcuts/ShortcutHint.cpp | 166 | ||||
| -rw-r--r-- | shortcuts/ShortcutHint.h | 53 | ||||
| -rw-r--r-- | shortcuts/ShortcutHintPrivate.cpp | 117 | ||||
| -rw-r--r-- | shortcuts/ShortcutHintPrivate.h | 41 | ||||
| -rw-r--r-- | shortcuts/ShortcutModel.cpp | 60 | ||||
| -rw-r--r-- | shortcuts/ShortcutModel.h | 64 | ||||
| -rw-r--r-- | shortcuts/ShortcutView.cpp | 299 | ||||
| -rw-r--r-- | shortcuts/ShortcutView.h | 88 | ||||
| -rw-r--r-- | shortcuts/StandaloneShortcuts.cpp | 105 |
14 files changed, 1572 insertions, 0 deletions
diff --git a/shortcuts/AbstractShortcutHint.h b/shortcuts/AbstractShortcutHint.h new file mode 100644 index 000000000..abd20a944 --- /dev/null +++ b/shortcuts/AbstractShortcutHint.h @@ -0,0 +1,104 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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_ABSTRACT_SHORTCUT_ICON_H +#define UNITYSHELL_ABSTRACT_SHORTCUT_ICON_H + +#include <string> + +#include <Nux/Nux.h> +#include <NuxCore/Property.h> + +namespace unity +{ +namespace shortcut +{ + +enum OptionType +{ + COMPIZ_KEY_OPTION = 0, + COMPIZ_METAKEY_OPTION, + COMPIZ_MOUSE_OPTION, + HARDCODED_OPTION + /* GSETTINGS_OPTION, + * GCONF_OPTION */ +}; + +class AbstractHint +{ +public: + typedef std::shared_ptr<AbstractHint> Ptr; + // Ctor + AbstractHint(std::string const& category, + std::string const& prefix, + std::string const& postfix, + std::string const& description, + OptionType const type, + std::string const& arg1, + std::string const& arg2 = "", + std::string const& arg3 = "") + : category(category) + , prefix(prefix) + , postfix(postfix) + , description(description) + , type(type) + , arg1(arg1) + , arg2(arg2) + , arg3(arg3) + { + } + + // Copy ctor + AbstractHint(unity::shortcut::AbstractHint const& obj) + : category(obj.category()) + , prefix(obj.prefix()) + , postfix(obj.postfix()) + , description(obj.description()) + , type(obj.type()) + , arg1(obj.arg1()) + , arg2(obj.arg2()) + , arg3(obj.arg3()) + , value(obj.value()) + , shortkey(obj.shortkey()) + { + } + + // Dtor + virtual ~AbstractHint(){}; + + // Public Methods + virtual bool Fill() = 0; + + // Properties + nux::Property<std::string> category; + nux::Property<std::string> prefix; + nux::Property<std::string> postfix; + nux::Property<std::string> description; + nux::Property<OptionType> type; + nux::Property<std::string> arg1; + nux::Property<std::string> arg2; + nux::Property<std::string> arg3; + nux::Property<std::string> value; + nux::Property<std::string> shortkey; +}; + +} // namespace shortcut +} // namespace unity + +#endif // UNITYSHELL_ABSTRACT_SHORTCUT_ICON_H diff --git a/shortcuts/CMakeLists.txt b/shortcuts/CMakeLists.txt new file mode 100644 index 000000000..0d9f1d651 --- /dev/null +++ b/shortcuts/CMakeLists.txt @@ -0,0 +1,51 @@ +set(UNITY_SRC ../plugins/unityshell/src) + +find_package (PkgConfig) + +set (CFLAGS + ${CACHED_UNITY_DEPS_CFLAGS} + ${CACHED_UNITY_DEPS_CFLAGS_OTHER} + ${MAINTAINER_CFLAGS} + "-DGETTEXT_PACKAGE=\"unity\"" + "-I${CMAKE_CURRENT_BINARY_DIR}" + ) + +if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") + set (CFLAGS ${CFLAGS} "-fPIC") +endif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") + +add_definitions (${CFLAGS}) + +set (LIBS ${CACHED_UNITY_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU") +link_libraries (${LIBS}) + +set (LIB_PATHS ${CACHED_UNITY_DEPS_LIBRARY_DIRS}) +link_directories (${CMAKE_BINARY_DIR}/UnityCore ${LIB_PATHS}) + +include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) + +# +# Headers & Sources +# +set (SHORTCUTS_SOURCES + AbstractShortcutHint.h + MockShortcutHint.h + ShortcutController.cpp + ShortcutController.h + ShortcutHint.cpp + ShortcutHintPrivate.cpp + ShortcutModel.cpp + ShortcutModel.h + ShortcutView.cpp + ShortcutView.h + ) + +add_library (shortcuts-lib STATIC ${SHORTCUTS_SOURCES}) +add_dependencies (shortcuts-lib unity-core-${UNITY_API_VERSION} unity-shared) + +# +# Standalone variant +# +add_executable (shortcuts StandaloneShortcuts.cpp) +add_dependencies (shortcuts shortcuts-lib) +target_link_libraries (shortcuts shortcuts-lib unity-shared) diff --git a/shortcuts/MockShortcutHint.h b/shortcuts/MockShortcutHint.h new file mode 100644 index 000000000..b0c3fbd22 --- /dev/null +++ b/shortcuts/MockShortcutHint.h @@ -0,0 +1,73 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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_MOCK_SHORTCUT_HINT_H +#define UNITYSHELL_MOCK_SHORTCUT_HINT_H + +#include "AbstractShortcutHint.h" + +namespace unity +{ +namespace shortcut +{ + +class MockHint : public AbstractHint +{ +public: + // Ctor and dtor + MockHint(std::string const& category, + std::string const& prefix, + std::string const& postfix, + std::string const& description, + OptionType const type, + std::string const& arg1, + std::string const& arg2 = "", + std::string const& arg3 = "") + : AbstractHint(category, prefix, postfix, description, type, arg1, arg2, arg3) + { + } + + ~MockHint() {}; + + // Methods... + bool Fill() + { + switch (type()) + { + case COMPIZ_MOUSE_OPTION: + case COMPIZ_KEY_OPTION: + case COMPIZ_METAKEY_OPTION: + value = arg1() + "-" + arg2(); + shortkey = prefix() + value() + postfix(); + return true; + + case HARDCODED_OPTION: + value = arg1(); + shortkey = prefix() + value() + postfix(); + return true; + } + + return false; + } +}; + +} // shortcut hint +} // namespace unity + +#endif // UNITYSHELL_MOCK_SHORTCUT_HINT_H diff --git a/shortcuts/ShortcutController.cpp b/shortcuts/ShortcutController.cpp new file mode 100644 index 000000000..9110a9947 --- /dev/null +++ b/shortcuts/ShortcutController.cpp @@ -0,0 +1,252 @@ +/* + * Copyright (C) 2011 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 "ShortcutController.h" + +#include "unity-shared/UBusMessages.h" +#include "unity-shared/WindowManager.h" + +namespace unity +{ +namespace shortcut +{ +namespace +{ +const unsigned int SUPER_TAP_DURATION = 650; +const unsigned int FADE_DURATION = 100; +} // anonymouse namespace; + +Controller::Controller(std::list<AbstractHint::Ptr>& hints) + : view_window_(0) + , visible_(false) + , enabled_(true) + , show_timer_(0) + , fade_in_animator_(FADE_DURATION) + , fade_out_animator_(FADE_DURATION) +{ + bg_color_ = nux::Color(0.0, 0.0, 0.0, 0.5); + + ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED, + sigc::mem_fun(this, &Controller::OnBackgroundUpdate)); + + ubus_manager_.RegisterInterest(UBUS_LAUNCHER_START_KEY_SWTICHER, [&] (GVariant*) { + enabled_ = false; + }); + + ubus_manager_.RegisterInterest(UBUS_LAUNCHER_END_KEY_SWTICHER, [&] (GVariant*) { + enabled_ = true; + }); + + ubus_manager_.RegisterInterest(UBUS_OVERLAY_SHOWN, [&] (GVariant*) { + Hide(); + }); + + ubus_manager_.SendMessage(UBUS_BACKGROUND_REQUEST_COLOUR_EMIT); + + model_.reset(new Model(hints)); + + model_->Fill(); + + fade_in_animator_.animation_updated.connect(sigc::mem_fun(this, &Controller::OnFadeInUpdated)); + fade_in_animator_.animation_ended.connect(sigc::mem_fun(this, &Controller::OnFadeInEnded)); + fade_out_animator_.animation_updated.connect(sigc::mem_fun(this, &Controller::OnFadeOutUpdated)); + fade_out_animator_.animation_ended.connect(sigc::mem_fun(this, &Controller::OnFadeOutEnded)); +} + +Controller::~Controller() +{ + if (view_window_) + view_window_->UnReference(); + + view_.Release(); +} + + +void Controller::OnFadeInUpdated(double opacity) +{ + view_window_->SetOpacity(opacity); +} + +void Controller::OnFadeInEnded() +{ + view_window_->SetOpacity(1.0); +} + +void Controller::OnFadeOutUpdated(double progress) +{ + double opacity = CLAMP(1.0f - progress, 0.0f, 1.0f); + view_window_->SetOpacity(opacity); +} + +void Controller::OnFadeOutEnded() +{ + view_window_->SetOpacity(0.0); +} + + +void Controller::OnBackgroundUpdate(GVariant* data) +{ + gdouble red, green, blue, alpha; + g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha); + bg_color_ = nux::Color(red, green, blue, alpha); + + if (view_) + view_->background_color = bg_color_; +} + +bool Controller::Show() +{ + if (show_timer_) + g_source_remove(show_timer_); + show_timer_ = 0; + + if (enabled_) + { + show_timer_ = g_timeout_add(SUPER_TAP_DURATION, &Controller::OnShowTimer, this); + model_->Fill(); + visible_ = true; + + return true; + } + + return false; +} + +gboolean Controller::OnShowTimer(gpointer data) +{ + Controller* self = static_cast<Controller*>(data); + + if (!self->enabled_) + { + return FALSE; + } + + self->EnsureView(); + + nux::Geometry geo; + if (!self->view_->GetBaseGeometry(geo)) + return FALSE; + self->view_window_->SetGeometry(geo); + + if (self->visible_) + { + self->view_->SetupBackground(true); + self->fade_out_animator_.Stop(); + self->fade_in_animator_.Start(self->view_window_->GetOpacity()); + } + + self->show_timer_ = 0; + return FALSE; +} + +void Controller::ConstructView() +{ + view_ = View::Ptr(new View()); + AddChild(view_.GetPointer()); + view_->SetModel(model_); + view_->background_color = bg_color_; + + if (!view_window_) + { + main_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION); + main_layout_->SetVerticalExternalMargin(0); + main_layout_->SetHorizontalExternalMargin(0); + + view_window_ = new nux::BaseWindow("ShortcutHint"); + view_window_->SinkReference(); + view_window_->SetLayout(main_layout_); + view_window_->SetBackgroundColor(nux::Color(0x00000000)); + } + + main_layout_->AddView(view_.GetPointer()); + + view_->SetupBackground(false); + view_window_->SetOpacity(0.0); + view_window_->ShowWindow(true); +} + +void Controller::EnsureView() +{ + if (!view_window_) + ConstructView(); +} + +void Controller::SetAdjustment(int x, int y) +{ + EnsureView(); + + view_->SetAdjustment(x, y); +} + + +void Controller::Hide() +{ + if (!visible_) + return; + + visible_ = false; + + if (show_timer_) + { + g_source_remove(show_timer_); + show_timer_ = 0; + } + + if (view_window_) + { + view_->SetupBackground(false); + fade_in_animator_.Stop(); + fade_out_animator_.Start(1.0 - view_window_->GetOpacity()); + } +} + +bool Controller::Visible() +{ + return visible_; +} + +bool Controller::IsEnabled() +{ + return enabled_; +} + +void Controller::SetEnabled(bool enabled) +{ + enabled_ = enabled; +} + +// +// Introspection +// +std::string Controller::GetName() const +{ + return "ShortcutController"; +} + +void Controller::AddProperties(GVariantBuilder* builder) +{ + unity::variant::BuilderWrapper(builder) + .add("timeout_duration", SUPER_TAP_DURATION + FADE_DURATION) + .add("enabled", IsEnabled()) + .add("about_to_show", (Visible() && !fade_out_animator_.IsRunning() && view_window_ && view_window_->GetOpacity() != 1.0f)) + .add("about_to_hide", (Visible() && !fade_in_animator_.IsRunning() && view_window_ && view_window_->GetOpacity() != 1.0f)) + .add("visible", (Visible() && view_window_ && view_window_->GetOpacity() == 1.0f)); +} + +} // namespace shortcut +} // namespace unity diff --git a/shortcuts/ShortcutController.h b/shortcuts/ShortcutController.h new file mode 100644 index 000000000..c05470484 --- /dev/null +++ b/shortcuts/ShortcutController.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2011 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_SHORTCUTCONTROLLER_H +#define UNITYSHELL_SHORTCUTCONTROLLER_H + +#include <boost/shared_ptr.hpp> + +#include <Nux/Nux.h> +#include <Nux/BaseWindow.h> +#include <Nux/HLayout.h> +#include <NuxCore/Color.h> +#include <UnityCore/Variant.h> + +#include "unity-shared/Animator.h" +#include "unity-shared/Introspectable.h" +#include "ShortcutModel.h" +#include "ShortcutView.h" +#include "unity-shared/UBusWrapper.h" + +namespace unity +{ +namespace shortcut +{ + +class Controller : public debug::Introspectable +{ +public: + typedef std::shared_ptr<Controller> Ptr; + + // Ctor and dtor + Controller(std::list<AbstractHint::Ptr>& hints); + ~Controller(); + + // Public Methods + bool Show(); + void Hide(); + + bool Visible(); + bool IsEnabled(); + + void SetAdjustment(int x, int y); + void SetEnabled(bool enabled); + +protected: + std::string GetName() const; + void AddProperties(GVariantBuilder* builder); + +private: + // Private Methods + void ConstructView(); + void EnsureView(); + void OnBackgroundUpdate(GVariant* data); + void OnFadeInUpdated(double opacity); + void OnFadeInEnded(); + void OnFadeOutUpdated(double opacity); + void OnFadeOutEnded(); + + static gboolean OnShowTimer(gpointer data); + + // Private Members + View::Ptr view_; + Model::Ptr model_; + + nux::Geometry workarea_; + nux::BaseWindow* view_window_; + nux::HLayout* main_layout_; + + bool visible_; + bool enabled_; + nux::Color bg_color_; + guint show_timer_; + + Animator fade_in_animator_; + Animator fade_out_animator_; + + UBusManager ubus_manager_; +}; + +} // namespace shortcut +} // namespace unity + +#endif //UNITYSHELL_SHORTCUTHINTCONTROLLER_H + diff --git a/shortcuts/ShortcutHint.cpp b/shortcuts/ShortcutHint.cpp new file mode 100644 index 000000000..a0105f562 --- /dev/null +++ b/shortcuts/ShortcutHint.cpp @@ -0,0 +1,166 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 "ShortcutHint.h" + +#include <core/core.h> // Compiz... +#include <NuxCore/Logger.h> + +#include "ShortcutHintPrivate.h" + +namespace unity +{ +namespace shortcut +{ +namespace +{ + nux::logging::Logger logger("unity.shortcut"); +} // anonymouse namespace + +// Ctor +Hint::Hint(std::string const& category, + std::string const& prefix, + std::string const& postfix, + std::string const& description, + OptionType const type, + std::string const& arg1, + std::string const& arg2, + std::string const& arg3) + : AbstractHint(category, prefix, postfix, description, type, arg1, arg2, arg3) +{ +} + +// Dtor +Hint::~Hint() +{ +} + +/* + * Gets and fills the shortcut value. + * Returns true if everything was OK, returns false otherwise. + * Use member property Value to get it. + */ +bool Hint::Fill() +{ + switch(type()) + { + case COMPIZ_MOUSE_OPTION: + { + // Arg1 = Plugin name + // Arg2 = key Option name + CompPlugin* p = CompPlugin::find(arg1().c_str()); + + if (!p) + return false; + + foreach (CompOption &opt, p->vTable->getOptions()) + { + if (opt.name() == arg2()) + { + std::string temp = impl::FixMouseShortcut(impl::FixShortcutFormat(opt.value().action().buttonToString())); + temp = impl::ProperCase(temp); + + if (value() != temp) + { + value = temp; + shortkey = prefix() + value() + postfix(); + } + + return true; + } + } + + break; + } + break; + + case COMPIZ_KEY_OPTION: + { + // Arg1 = Plugin name + // Arg2 = key Option name + CompPlugin* p = CompPlugin::find(arg1().c_str()); + + if (!p) + return false; + + foreach (CompOption &opt, p->vTable->getOptions()) + { + if (opt.name() == arg2()) + { + std::string temp(impl::GetTranslatableLabel(opt.value().action().keyToString())); + temp = impl::ProperCase(temp); + + if (value() != temp) + { + value = temp; + shortkey = prefix() + value() + postfix(); + } + + return true; + } + } + + break; + } + case COMPIZ_METAKEY_OPTION: + { + // Arg1 = Plugin name + // Arg2 = key Option name + CompPlugin* p = CompPlugin::find(arg1().c_str()); + + if (!p) + return false; + + foreach (CompOption &opt, p->vTable->getOptions()) + { + if (opt.name() == arg2()) + { + std::string temp(impl::GetMetaKey(opt.value().action().keyToString())); + temp = impl::GetTranslatableLabel(temp); + temp = impl::ProperCase(temp); + + if (value() != temp) + { + value = temp; + shortkey = prefix() + value() + postfix(); + } + + return true; + } + } + + break; + } + case HARDCODED_OPTION: + if (value != arg1()) + { + value = arg1(); + shortkey = prefix() + value() + postfix(); + } + return true; + + default: + LOG_WARNING(logger) << "Unable to find the option type" << type(); + } + + return false; +} + +} // namespace shortcut +} // namespace unity diff --git a/shortcuts/ShortcutHint.h b/shortcuts/ShortcutHint.h new file mode 100644 index 000000000..529e96b54 --- /dev/null +++ b/shortcuts/ShortcutHint.h @@ -0,0 +1,53 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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_SHORTCUTHINT_H +#define UNITYSHELL_SHORTCUTHINT_H + +#include "AbstractShortcutHint.h" + +namespace unity +{ +namespace shortcut +{ + +class Hint : public AbstractHint +{ +public: + // Ctor + Hint(std::string const& category, + std::string const& prefix, + std::string const& postfix, + std::string const& description, + OptionType const type, + std::string const& arg1, + std::string const& arg2 = "", + std::string const& arg3 = ""); + + // Dtor + ~Hint(); + + // Public methods + bool Fill(); +}; + +} // namespace shortcut +} // namespace unity + + #endif // UNITYSHELL_SHORTCUTHINT_H diff --git a/shortcuts/ShortcutHintPrivate.cpp b/shortcuts/ShortcutHintPrivate.cpp new file mode 100644 index 000000000..232538efd --- /dev/null +++ b/shortcuts/ShortcutHintPrivate.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2011 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 <glib/gi18n-lib.h> +#include <gtk/gtk.h> + +#include "ShortcutHintPrivate.h" +#include "UnityCore/GLibWrapper.h" + +#include <boost/algorithm/string/replace.hpp> + +namespace unity +{ +namespace shortcut +{ +namespace impl +{ + +std::string GetMetaKey(std::string const& scut) +{ + size_t index = scut.find_last_of( ">"); + if (index >= 0) + return std::string(scut.begin(), scut.begin() + index + 1); + else + return ""; +} + +std::string FixShortcutFormat(std::string const& scut) +{ + std::string ret(scut.begin(), scut.end() - 1); + + boost::replace_all(ret, "<", ""); + boost::replace_all(ret, ">", " + "); + + if (scut[scut.size()-1] != '>') + ret += scut[scut.size()-1]; + + return ret; +} + +std::string GetTranslatableLabel(std::string const& scut) +{ + guint accelerator_key; + GdkModifierType accelerator_mods; + + gtk_accelerator_parse(scut.c_str(), + &accelerator_key, + &accelerator_mods); + + std::string temp(glib::String(gtk_accelerator_get_label(accelerator_key, accelerator_mods)).Str()); + + // gtk_accelerator_get_label adds an extra '+' at the end of the label. + if (temp.length() > 0) + { + std::string::iterator it = temp.end() - 1; + if (*it == '+') + temp.erase(it); + } + + // Adds an extra space around the '+'. + boost::replace_all(temp, "+", " + "); + + return temp; +} + +std::string FixMouseShortcut(std::string const& scut) +{ + std::string ret(scut); + + boost::replace_all(ret, "Button1", _("Left Mouse")); + boost::replace_all(ret, "Button2", _("Middle Mouse")); + boost::replace_all(ret, "Button3", _("Right Mouse")); + + return ret; +} + +std::string ProperCase(std::string const& str) +{ + std::string ret = str; + + bool cap_next = true; + + for (unsigned int i = 0; i < ret.length(); ++i) + { + if (cap_next and isalpha(ret[i])) + { + ret[i]=toupper(ret[i]); + cap_next = false; + } + else + { + cap_next = ispunct(ret[i]) || isspace(ret[i]); + } + } + + return ret; +} + +} // namespace impl +} // namespace shortcut +} // namespace unity + diff --git a/shortcuts/ShortcutHintPrivate.h b/shortcuts/ShortcutHintPrivate.h new file mode 100644 index 000000000..c335733e3 --- /dev/null +++ b/shortcuts/ShortcutHintPrivate.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011 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_SHORTCUT_HINT_PRIVATE_H +#define UNITYSHELL_SHORTCUT_HINT_PRIVATE_H + +#include <string> + +namespace unity +{ +namespace shortcut +{ +namespace impl +{ + +std::string GetMetaKey(std::string const& scut); +std::string FixShortcutFormat(std::string const& scut); +std::string GetTranslatableLabel(std::string const& scut); +std::string FixMouseShortcut(std::string const& scut); +std::string ProperCase(std::string const& str); + +} // namespace impl +} // namespace shortcut +} // namespace unity + +#endif // UNITYSHELL_SHORTCUT_HINT_PRIVATE_H diff --git a/shortcuts/ShortcutModel.cpp b/shortcuts/ShortcutModel.cpp new file mode 100644 index 000000000..c318bd898 --- /dev/null +++ b/shortcuts/ShortcutModel.cpp @@ -0,0 +1,60 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 "ShortcutModel.h" + +namespace unity +{ +namespace shortcut +{ + +// Ctor +Model::Model(std::list<AbstractHint::Ptr>& hints) +{ + for (auto hint : hints) + AddHint(hint); +} + +// Dtor +Model::~Model() +{ +} + + +void Model::AddHint(AbstractHint::Ptr hint) +{ + if (!hint) + return; + + if (hints_.find(hint->category()) == hints_.end()) + categories_.push_back(hint->category()); + + hints_[hint->category()].push_back(hint); +} + + +void Model::Fill() +{ + for (auto category : categories_) + for (auto item : hints_[category]) + item->Fill(); +} + +} // namespace shortcut +} // namespace unity diff --git a/shortcuts/ShortcutModel.h b/shortcuts/ShortcutModel.h new file mode 100644 index 000000000..7344d372b --- /dev/null +++ b/shortcuts/ShortcutModel.h @@ -0,0 +1,64 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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_SHORTCUSMODEL_H +#define UNITYSHELL_SHORTCUSMODEL_H + +#include <boost/noncopyable.hpp> +#include <map> +#include <memory> +#include <list> +#include <string> +#include <vector> + +#include "AbstractShortcutHint.h" + +namespace unity +{ +namespace shortcut +{ + +class Model : boost::noncopyable +{ +public: + typedef std::shared_ptr<Model> Ptr; + + // Ctor and dtor + Model(std::list<AbstractHint::Ptr>& hints); + ~Model(); + + // Accessors + std::vector<std::string>& categories() { return categories_; } + std::map<std::string, std::list<AbstractHint::Ptr>>& hints() { return hints_; } + + void Fill(); + +private: + // Private functions + void AddHint(AbstractHint::Ptr hint); + + // Private members + std::vector<std::string> categories_; + std::map<std::string, std::list<AbstractHint::Ptr>> hints_; +}; + +} // shortcut +} // unity + +#endif // UNITYSHELL_SHORTCUTS_H diff --git a/shortcuts/ShortcutView.cpp b/shortcuts/ShortcutView.cpp new file mode 100644 index 000000000..564d270b5 --- /dev/null +++ b/shortcuts/ShortcutView.cpp @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2011 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> + * Jay Taoko <jay.taoko@canonical.com> + */ + +#include "ShortcutView.h" + +#include <glib/gi18n-lib.h> +#include <boost/algorithm/string.hpp> +#include <UnityCore/GLibWrapper.h> + +#include "unity-shared/LineSeparator.h" +#include "unity-shared/StaticCairoText.h" +#include "unity-shared/UScreen.h" + +namespace unity +{ +namespace shortcut +{ +namespace +{ + int SECTION_NAME_FONT_SIZE = 17/1.33; + int SHORTKEY_ENTRY_FONT_SIZE = 13/1.33; + int INTER_SPACE_SHORTKEY_DESCRIPTION = 10; + int SHORTKEY_COLUMN_WIDTH = 150; + int DESCRIPTION_COLUMN_WIDTH = 265; + int LINE_SPACING = 5; + + // We need this class because SetVisible doesn't work for layouts. + class SectionView : public nux::View + { + public: + SectionView(NUX_FILE_LINE_DECL) + : nux::View(NUX_FILE_LINE_PARAM) + { + } + + protected: + void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) + { + } + + void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) + { + if (GetLayout()) + GetLayout()->ProcessDraw(graphics_engine, force_draw); + } + }; + +} // unnamed namespace + +NUX_IMPLEMENT_OBJECT_TYPE(View); + +View::View() + : ui::UnityWindowView() + , x_adjustment_(0) + , y_adjustment_(0) +{ + layout_ = new nux::VLayout(); + layout_->SetPadding(50, 38); + layout_->SetSpaceBetweenChildren(20); + SetLayout(layout_); + + std::string header = "<b>"; + header += _("Keyboard Shortcuts"); + header += "</b>"; + + nux::StaticText* header_view = new nux::StaticText(header, NUX_TRACKER_LOCATION); + header_view->SetTextPointSize(20/1.33); + header_view->SetFontName("Ubuntu"); + layout_->AddView(header_view, 1 , nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + + layout_->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + + columns_layout_ = new nux::HLayout(); + columns_layout_->SetSpaceBetweenChildren(30); + layout_->AddLayout(columns_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + + // Column 1... + columns_.push_back(new nux::VLayout()); + columns_layout_->AddLayout(columns_[0], 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + + // Column 2... + columns_.push_back(new nux::VLayout()); + columns_layout_->AddLayout(columns_[1], 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); +} + +View::~View() +{ +} + +void View::SetModel(Model::Ptr model) +{ + model_ = model; + + // Fills the columns... + RenderColumns(); +} + +Model::Ptr View::GetModel() +{ + return model_; +} + +void View::SetAdjustment(int x, int y) +{ + x_adjustment_ = x; + y_adjustment_ = y; +} + +bool View::GetBaseGeometry(nux::Geometry& geo) +{ + UScreen* uscreen = UScreen::GetDefault(); + int primary_monitor = uscreen->GetMonitorWithMouse(); + auto monitor_geo = uscreen->GetMonitorGeometry(primary_monitor); + + int w = GetAbsoluteWidth(); + int h = GetAbsoluteHeight(); + + if (x_adjustment_ + w > monitor_geo.width || + y_adjustment_ + h > monitor_geo.height) + return false; + + geo.width = w; + geo.height = h; + + geo.x = monitor_geo.x + x_adjustment_ + (monitor_geo.width - geo.width - x_adjustment_) / 2; + geo.y = monitor_geo.y + y_adjustment_ + (monitor_geo.height - geo.height - y_adjustment_) / 2; + return true; +} + +nux::LinearLayout* View::CreateSectionLayout(const char* section_name) +{ + nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION); + + std::string name("<b>"); + name += glib::String(g_markup_escape_text(section_name, -1)).Str(); + name += "</b>"; + + nux::StaticText* section_name_view = new nux::StaticText(name, NUX_TRACKER_LOCATION); + section_name_view->SetTextPointSize(SECTION_NAME_FONT_SIZE); + section_name_view->SetFontName("Ubuntu"); + layout->AddView(new nux::SpaceLayout(10, 10, 10, 10), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT); + layout->AddView(section_name_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT); + layout->AddView(new nux::SpaceLayout(15, 15, 15, 15), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT); + + return layout; +} + +nux::View* View::CreateShortKeyEntryView(AbstractHint::Ptr const& hint) +{ + nux::View* view = new SectionView(NUX_TRACKER_LOCATION); + + nux::HLayout* layout = new nux::HLayout("EntryLayout", NUX_TRACKER_LOCATION); + view->SetLayout(layout); + + nux::HLayout* shortkey_layout = new nux::HLayout(NUX_TRACKER_LOCATION); + nux::HLayout* description_layout = new nux::HLayout(NUX_TRACKER_LOCATION); + + glib::String shortkey(g_markup_escape_text(hint->shortkey().c_str(), -1)); + + std::string skey = "<b>"; + skey += shortkey.Str(); + skey += "</b>"; + + nux::StaticText* shortkey_view = new nux::StaticText(skey, NUX_TRACKER_LOCATION); + shortkey_view->SetTextAlignment(nux::StaticText::ALIGN_LEFT); + shortkey_view->SetFontName("Ubuntu"); + shortkey_view->SetTextPointSize(SHORTKEY_ENTRY_FONT_SIZE); + shortkey_view->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH); + shortkey_view->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH); + + glib::String es_desc(g_markup_escape_text(hint->description().c_str(), -1)); + + nux::StaticText* description_view = new nux::StaticText(es_desc.Value(), NUX_TRACKER_LOCATION); + description_view->SetTextAlignment(nux::StaticText::ALIGN_LEFT); + shortkey_view->SetFontName("Ubuntu"); + description_view->SetTextPointSize(SHORTKEY_ENTRY_FONT_SIZE); + description_view->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH); + description_view->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH); + + shortkey_layout->AddView(shortkey_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); + shortkey_layout->SetContentDistribution(nux::MAJOR_POSITION_START); + shortkey_layout->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH); + shortkey_layout->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH); + + description_layout->AddView(description_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); + description_layout->SetContentDistribution(nux::MAJOR_POSITION_START); + description_layout->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH); + description_layout->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH); + + layout->AddLayout(shortkey_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); + layout->AddLayout(description_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT); + layout->SetSpaceBetweenChildren(INTER_SPACE_SHORTKEY_DESCRIPTION); + description_layout->SetContentDistribution(nux::MAJOR_POSITION_START); + + auto on_shortkey_changed = [](std::string const& new_shortkey, nux::View* main_view, nux::StaticText* view) { + std::string skey("<b>"); + skey += new_shortkey; + skey += "</b>"; + + view->SetText(skey); + main_view->SetVisible(!new_shortkey.empty()); + }; + + hint->shortkey.changed.connect(sigc::bind(sigc::slot<void, std::string const&, nux::View*, nux::StaticText*>(on_shortkey_changed), view, shortkey_view)); + + return view; +} + +nux::LinearLayout* View::CreateIntermediateLayout() +{ + nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION); + layout->SetSpaceBetweenChildren(LINE_SPACING); + + return layout; +} + +nux::Geometry View::GetBackgroundGeometry() +{ + nux::Geometry base = GetGeometry(); + nux::Geometry background_geo; + + background_geo.width = base.width; + background_geo.height = base.height; + background_geo.x = (base.width - background_geo.width)/2; + background_geo.y = (base.height - background_geo.height)/2; + + return background_geo; +} + +void View::DrawOverlay(nux::GraphicsEngine& GfxContext, bool force_draw, nux::Geometry clip) +{ + layout_->ProcessDraw(GfxContext, force_draw); +} + +void View::RenderColumns() +{ + int i = 0; + int column = 0; + + for (auto category : model_->categories()) + { + // Three sections in the fist column... + if (i > 2) + column = 1; + + nux::LinearLayout* section_layout = CreateSectionLayout(category.c_str()); + nux::LinearLayout* intermediate_layout = CreateIntermediateLayout(); + intermediate_layout->SetContentDistribution(nux::MAJOR_POSITION_START); + + for (auto hint : model_->hints()[category]) + { + nux::View* view = CreateShortKeyEntryView(hint); + view->SetVisible(!hint->shortkey().empty()); + intermediate_layout->AddView(view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL); + } + + section_layout->AddLayout(intermediate_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + + if (i == 0 or i==1 or i==3 or i==4) + { + // Add space before the line + section_layout->AddView(new nux::SpaceLayout(23, 23, 23, 23), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT); + section_layout->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + // Add space after the line + section_layout->AddView(new nux::SpaceLayout(20, 20, 20, 20), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT); + } + + columns_[column]->AddView(section_layout, 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL); + + i++; + } +} + +// +// Introspectable methods +// +std::string View::GetName() const +{ + return "ShortcutView"; +} + +} // namespace shortcut +} // namespace unity diff --git a/shortcuts/ShortcutView.h b/shortcuts/ShortcutView.h new file mode 100644 index 000000000..bf4685699 --- /dev/null +++ b/shortcuts/ShortcutView.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011 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_SHORTCUTVIEW_H +#define UNITYSHELL_SHORTCUTVIEW_H + +#include <Nux/Nux.h> +#include <Nux/GridHLayout.h> +#include <Nux/HLayout.h> +#include <NuxCore/ObjectPtr.h> +#include <NuxCore/Property.h> +#include <Nux/StaticText.h> +#include <Nux/View.h> +#include <Nux/VLayout.h> + +#include "unity-shared/UnityWindowView.h" +#include "unity-shared/BackgroundEffectHelper.h" +#include "ShortcutModel.h" + +namespace unity +{ +namespace shortcut +{ + +class View : public ui::UnityWindowView +{ + NUX_DECLARE_OBJECT_TYPE(View, ui::UnityWindowView); +public: + typedef nux::ObjectPtr<View> Ptr; + + // Ctor and dtor + View(); + ~View(); + + // Public methods + bool GetBaseGeometry(nux::Geometry&); + void SetAdjustment(int x, int y); + void SetModel(Model::Ptr model); + Model::Ptr GetModel(); + +protected: + // Protected methods + void DrawOverlay(nux::GraphicsEngine& GfxContext, bool force_draw, nux::Geometry clip); + nux::Geometry GetBackgroundGeometry(); + + // Introspectable methods + std::string GetName() const; + +private: + // Private methods + nux::LinearLayout* CreateSectionLayout(const char* section_name); + nux::View* CreateShortKeyEntryView(AbstractHint::Ptr const& hint); + nux::LinearLayout* CreateIntermediateLayout(); + + void RenderColumns(); + + // Private members + Model::Ptr model_; + + nux::VLayout* layout_; + nux::HLayout* columns_layout_; + std::vector<nux::VLayout*> columns_; + + int x_adjustment_; + int y_adjustment_; +}; + +} // namespace shortcut + +} // namespace unity + +#endif // UNITYSHELL_SHORTCUTVIEW_H + diff --git a/shortcuts/StandaloneShortcuts.cpp b/shortcuts/StandaloneShortcuts.cpp new file mode 100644 index 000000000..e989b4d3a --- /dev/null +++ b/shortcuts/StandaloneShortcuts.cpp @@ -0,0 +1,105 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011 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 <dbus/dbus-glib.h> +#include <glib/gi18n-lib.h> +#include <gtk/gtk.h> +#include <Nux/Nux.h> +#include <Nux/WindowThread.h> + +#include "unity-shared/BackgroundEffectHelper.h" +#include "MockShortcutHint.h" +#include "ShortcutController.h" + +using namespace unity; + +static shortcut::Controller::Ptr controller; + +void ThreadWidgetInit(nux::NThread* thread, void* InitData) +{ + std::list<std::shared_ptr<shortcut::AbstractHint>> hints; + + // Launcher... + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" (Press)"), _("Open Launcher, displays shortcuts."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher" ))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", "", _("Open Launcher keyboard navigation mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "keyboard_focus"))); + // FIXME: Implemstd::shared_ptr<shortcut::AbstractHint>(ent it... + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", "", _("Switch application via Launcher."), shortcut::HARDCODED_OPTION, "Super + Tab"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" + 1 to 9"), _("Same as clicking on a Launcher icon."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", _(" + Shift + 1 to 9"), _("Open a new window of the app."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Launcher"), "", " + T", _("Open the Trash."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"))); + + // Dash... + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", _(" (Tap)"), _("Open the Dash Home."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"))); + // These are notstd::shared_ptr<shortcut::AbstractHint>( really hardcoded... + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", " + A", _("Open the Dash App Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", " + F", _("Open the Dash Files Lens."), shortcut::COMPIZ_KEY_OPTION,"unityshell", "show_launcher"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", " + M", _("Open the Dash Music Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "", _("Switches between Lenses."), shortcut::HARDCODED_OPTION, "Ctrl + Tab"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "", _("Moves the focus."), shortcut::HARDCODED_OPTION, _("Cursor Keys")))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "", _("Open currently focused item."), shortcut::HARDCODED_OPTION, _("Enter / Return")))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Dash"), "", "", _("'Run Command' mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "execute_command"))); + + // Menu Bar + // Is it really std::shared_ptr<shortcut::AbstractHint>(hard coded? + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Menu Bar"), "", "", _("Reveals application menu."), shortcut::HARDCODED_OPTION, "Alt"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Menu Bar"), "", "", _("Opens the indicator menu."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "panel_first_menu"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Menu Bar"), "", "", _("Moves focus between indicators."), shortcut::HARDCODED_OPTION, _("Cursor Left & Right")))); + + // Switching + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "", _("Switch between applications."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_forward"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "", _("Switch windows of current application."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_next_window"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "", _("Close window switch, return to app switch."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_detail_stop"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Switching"), "", "", _("Moves the foucs."), shortcut::HARDCODED_OPTION, _("Cursor Left & Right")))); + + // Workspaces + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Workspaces"), "", "", _("Spread workspaces."), shortcut::COMPIZ_KEY_OPTION, "expo", "expo_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Workspaces"), "", "", _("Switch workspaces."), shortcut::HARDCODED_OPTION, _("Cursor Keys")))); + //hints.push_bacstd::shared_ptr<shortcut::AbstractHint>(k(new shortcut::MockHint(_("Workspaces"), "", "", _("Move focused window to other workspace."), ...) + + // Windows + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Spreads all windows in current workspace."), shortcut::COMPIZ_KEY_OPTION, "scale", "initiate_output_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Minimises all windows."), shortcut::COMPIZ_KEY_OPTION, "core", "show_desktop_key"))); + // I don't know std::shared_ptr<shortcut::AbstractHint>(if it is really hardcoded, but I can't find where this option is stored. + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Open window accessibility menu."), shortcut::HARDCODED_OPTION, "Alt+Space"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Maximises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "maximize_window_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Un-maximises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "unmaximize_window_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Minimises current window."), shortcut::COMPIZ_KEY_OPTION, "core", "minimize_window_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Resizes current window."), shortcut::COMPIZ_KEY_OPTION, "resize", "initiate_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Closes current window."), shortcut::COMPIZ_KEY_OPTION, "core", "close_window_key"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Places window in corresponding positions."), shortcut::HARDCODED_OPTION, "Ctrl + Alt + Num"))); + hints.push_back(std::shared_ptr<shortcut::AbstractHint>(new shortcut::MockHint(_("Windows"), "", "", _("Move window."), shortcut::COMPIZ_KEY_OPTION, "move", "initiate_key"))); + + controller.reset(new shortcut::Controller(hints)); + controller->Show(); +} + +int main(int argc, char** argv) +{ + g_type_init(); + gtk_init(&argc, &argv); + + nux::NuxInitialize(0); + + BackgroundEffectHelper::blur_type = BLUR_NONE; + nux::WindowThread* wt = nux::CreateGUIThread(TEXT("Unity Shortcut Hint Overlay"), 1200, 720, 0, &ThreadWidgetInit, 0); + + wt->Run(NULL); + delete wt; + return 0; +} |
