diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2015-02-02 14:41:16 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2015-02-02 14:41:16 +0100 |
| commit | a0318caa976c916a074071a65f1af6b0ee661f22 (patch) | |
| tree | b6f7540a4c789b6617d4c9818654825e98424ccc /unity-shared | |
| parent | 332972e09044d97b601ce0e5ad531751579fb517 (diff) | |
MenuManager: update ShowNow property on entries based on the current active window
(bzr r3899.2.39)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/MenuManager.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/unity-shared/MenuManager.cpp b/unity-shared/MenuManager.cpp index 7a9341e75..b67e90078 100644 --- a/unity-shared/MenuManager.cpp +++ b/unity-shared/MenuManager.cpp @@ -26,6 +26,7 @@ #include <unordered_map> #include "MenuManager.h" +#include "WindowManager.h" namespace unity { @@ -48,6 +49,7 @@ struct Manager::Impl : sigc::trackable : parent_(parent) , indicators_(indicators) , key_grabber_(grabber) + , show_now_window_(0) , settings_(g_settings_new(SETTINGS_NAME.c_str())) { for (auto const& indicator : indicators_->GetIndicators()) @@ -116,7 +118,7 @@ struct Manager::Impl : sigc::trackable auto key = gdk_keyval_to_lower(gdk_unicode_to_keyval(mnemonic)); glib::String accelerator(gtk_accelerator_name(key, GDK_MOD1_MASK)); auto action = std::make_shared<CompAction>(); - auto id = entry->id(); + auto const& id = entry->id(); action->keyFromString(accelerator); action->setState(CompAction::StateInitKey); @@ -146,15 +148,39 @@ struct Manager::Impl : sigc::trackable parent_->key_activate_entry.emit(entry_id); } - void ShowMenus(bool show) + void SetShowNowForWindow(Window xid, bool show) { if (!appmenu_) return; - for (auto const& entry : appmenu_->GetEntries()) + show_now_window_ = show ? xid : 0; + + for (auto const& entry : appmenu_->GetEntriesForWindow(xid)) entry->set_show_now(show); } + void ShowMenus(bool show) + { + if (!appmenu_) + return; + + auto& wm = WindowManager::Default(); + + if (show) + { + active_win_conn_ = wm.window_focus_changed.connect([this] (Window new_active) { + SetShowNowForWindow(show_now_window_, false); + SetShowNowForWindow(new_active, true); + }); + } + else + { + active_win_conn_->disconnect(); + } + + SetShowNowForWindow(wm.GetActiveWindow(), show); + } + void IconPathsChanged() { auto const& icon_paths = indicators_->IconPaths(); @@ -170,7 +196,9 @@ struct Manager::Impl : sigc::trackable Indicators::Ptr indicators_; AppmenuIndicator::Ptr appmenu_; key::Grabber::Ptr key_grabber_; + Window show_now_window_; connection::Manager appmenu_connections_; + connection::Wrapper active_win_conn_; glib::Object<GSettings> settings_; glib::SignalManager signals_; std::unordered_map<std::string, std::shared_ptr<CompAction>> entry_actions_; |
