~3v1n0/unity/gnome-keys-timestamp-api

« back to all changes in this revision

Viewing changes to UnityCore/AppmenuIndicator.cpp

  • Committer: CI Train Bot
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2015-02-19 19:33:36 UTC
  • mfrom: (3899.2.85 lim-everywhere)
  • Revision ID: ci-train-bot@canonical.com-20150219193336-1ax9aswzdijrfq0f
Decorations, Panel: add menus for unfocused windows as well

Now the indicator-appmenu exports the menus for all the windows,
then it's up to us to filter them based on their parent window and
show on relevant place.
Also, set LIM as default now. Fixes: #1309778
Approved by: Andrea Azzarone, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
18
18
 */
19
19
 
20
 
#include "GLibSource.h"
 
20
#include <unordered_set>
 
21
 
21
22
#include "AppmenuIndicator.h"
 
23
#include "ConnectionManager.h"
22
24
 
23
25
namespace unity
24
26
{
25
27
namespace indicator
26
28
{
 
29
namespace
 
30
{
 
31
const Indicator::Entries empty_entries_;
 
32
}
27
33
 
28
34
struct AppmenuIndicator::Impl
29
35
{
30
36
  Impl(AppmenuIndicator* parent)
31
37
  {
32
 
    // When the active window has changed we might need to emit an updated signal
33
 
    parent->active_window.changed.connect([this, parent] (unsigned long) {
34
 
      update_wait_.reset(new glib::Timeout(250, [parent] {
35
 
        parent->updated.emit();
36
 
        return false;
37
 
      }));
38
 
    });
39
 
 
40
 
    parent->updated.connect([this] { update_wait_.reset(); });
 
38
    connections_.Add(parent->on_entry_added.connect([this] (Entry::Ptr const& entry) {
 
39
      window_entries_[entry->parent_window()].push_back(entry);
 
40
    }));
 
41
 
 
42
    connections_.Add(parent->on_entry_removed.connect([this] (Entry::Ptr const& entry) {
 
43
      auto it = window_entries_.find(entry->parent_window());
 
44
 
 
45
      if (it != window_entries_.end())
 
46
      {
 
47
        auto& entries = it->second;
 
48
        entries.erase(std::remove(entries.begin(), entries.end(), entry), entries.end());
 
49
 
 
50
        if (entries.empty())
 
51
          window_entries_.erase(it);
 
52
      }
 
53
    }));
41
54
  }
42
55
 
43
 
  glib::Source::UniquePtr update_wait_;
 
56
  connection::Manager connections_;
 
57
  std::unordered_map<uint32_t, Indicator::Entries> window_entries_;
44
58
};
45
59
 
46
60
AppmenuIndicator::AppmenuIndicator(std::string const& name)
47
61
  : Indicator(name)
48
 
  , active_window(0)
49
62
  , impl_(new AppmenuIndicator::Impl(this))
50
63
{}
51
64
 
52
65
AppmenuIndicator::~AppmenuIndicator()
53
66
{}
54
67
 
 
68
void AppmenuIndicator::Sync(Indicator::Entries const& entries)
 
69
{
 
70
  std::unordered_set<uint32_t> changed_windows;
 
71
  connection::Wrapper added_conn(on_entry_added.connect([this, &changed_windows] (Entry::Ptr const& entry) {
 
72
    changed_windows.insert(entry->parent_window());
 
73
  }));
 
74
 
 
75
  connection::Wrapper rm_conn(on_entry_removed.connect([this, &changed_windows] (Entry::Ptr const& entry) {
 
76
    changed_windows.insert(entry->parent_window());
 
77
  }));
 
78
 
 
79
  Indicator::Sync(entries);
 
80
 
 
81
  for (uint32_t win : changed_windows)
 
82
    updated_win.emit(win);
 
83
}
 
84
 
 
85
Indicator::Entries const& AppmenuIndicator::GetEntriesForWindow(uint32_t parent_window) const
 
86
{
 
87
  auto it = impl_->window_entries_.find(parent_window);
 
88
 
 
89
  if (it != impl_->window_entries_.end())
 
90
    return it->second;
 
91
 
 
92
  return empty_entries_;
 
93
}
 
94
 
55
95
void AppmenuIndicator::ShowAppmenu(unsigned int xid, int x, int y) const
56
96
{
57
97
  on_show_appmenu.emit(xid, x, y);