~thalexander/unity/update-fsf-address

« back to all changes in this revision

Viewing changes to unity-shared/GnomeKeyGrabber.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2016-03-07 18:51:47 UTC
  • mfrom: (4080 unity)
  • mto: This revision was merged to the branch mainline in revision 4085.
  • Revision ID: mail@3v1n0.net-20160307185147-0p1m89up4tqfb6w1
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
std::string const DBUS_NAME = "com.canonical.Unity.Test.GnomeKeyGrabber";
65
65
}
66
66
 
67
 
namespace
68
 
{
69
 
inline int compiz_event_timestamp(CompOption::Vector& options) { return options[7].value().i(); }
70
 
}
71
 
 
72
67
GnomeGrabber::Impl::Impl(bool test_mode)
73
68
  : screen_(screen)
74
69
  , shell_server_(test_mode ? testing::DBUS_NAME : shell::DBUS_NAME)
103
98
  auto it = std::find(actions_.begin(), actions_.end(), action);
104
99
  if (it != actions_.end())
105
100
  {
106
 
    action_id = actions_ids_[it - actions_.begin()];
 
101
    auto action_index = it - actions_.begin();
 
102
    action_id = actions_ids_[action_index];
 
103
    ++actions_customers_[action_index];
107
104
    LOG_DEBUG(logger) << "Key binding \"" << action.keyToString() << "\" is already grabbed, reusing id " << action_id;
108
105
    return true;
109
106
  }
112
109
  {
113
110
    actions_ids_.push_back(action_id);
114
111
    actions_.push_back(action);
 
112
    actions_customers_.push_back(1);
115
113
    return true;
116
114
  }
117
115
 
153
151
  if (!index || index >= actions_.size())
154
152
    return false;
155
153
 
 
154
  if (actions_customers_[index] > 1)
 
155
  {
 
156
    LOG_DEBUG(logger) << "Not removing action " << actions_[index].keyToString()
 
157
                      << " as it is used by multiple customers ("
 
158
                      << actions_customers_[index] << ")";
 
159
 
 
160
    --actions_customers_[index];
 
161
    return false;
 
162
  }
 
163
 
156
164
  CompAction* action = &(actions_[index]);
157
165
  LOG_DEBUG(logger) << "RemoveAction (\"" << action->keyToString() << "\")";
158
166
 
159
167
  screen_->removeAction(action);
160
168
  actions_.erase(actions_.begin() + index);
161
169
  actions_ids_.erase(actions_ids_.begin() + index);
 
170
  actions_customers_.erase(actions_customers_.begin() + index);
162
171
 
163
172
  return true;
164
173
}
224
233
    action.setState(CompAction::StateInitKey);
225
234
    action.setInitiate([this, action_id](CompAction* action, CompAction::State state, CompOption::Vector& options) {
226
235
      LOG_DEBUG(logger) << "pressed \"" << action->keyToString() << "\"";
227
 
      ActivateDBusAction(*action, action_id, 0, compiz_event_timestamp(options));
 
236
      ActivateDBusAction(*action, action_id, 0, CompOption::getIntOptionNamed(options, "time"));
228
237
      return true;
229
238
    });
230
239
  }
239
248
      if (state & CompAction::StateTermTapped)
240
249
      {
241
250
        LOG_DEBUG(logger) << "tapped \"" << key << "\"";
242
 
        ActivateDBusAction(*action, action_id, 0, compiz_event_timestamp(options));
 
251
        ActivateDBusAction(*action, action_id, 0, CompOption::getIntOptionNamed(options, "time"));
243
252
        return true;
244
253
      }
245
254
 
263
272
        if (it != actions_by_owner_.end())
264
273
        {
265
274
          for (auto action_id : it->second.actions)
266
 
            RemoveActionForOwner(action_id, name);
 
275
            RemoveActionByID(action_id);
267
276
 
268
277
          actions_by_owner_.erase(it);
269
278
        }
289
298
    if (actions.empty())
290
299
      actions_by_owner_.erase(it);
291
300
 
292
 
    return RemoveActionForOwner(action_id, owner);
 
301
    return RemoveActionByID(action_id);
293
302
  }
294
303
 
295
304
  LOG_WARN(logger) << "Action " << action_id << " was not registered by " << owner << ". "
297
306
  return false;
298
307
}
299
308
 
300
 
bool GnomeGrabber::Impl::RemoveActionForOwner(uint32_t action_id, std::string const& owner)
301
 
{
302
 
  for (auto it = actions_by_owner_.begin(); it != actions_by_owner_.end(); ++it)
303
 
  {
304
 
    if (it->first == owner)
305
 
      continue;
306
 
 
307
 
    auto const& actions = it->second.actions;
308
 
    if (actions.find(action_id) != actions.end())
309
 
    {
310
 
      LOG_DEBUG(logger) << "Action " << action_id << " registered for multiple destinations, not removed";
311
 
      return false;
312
 
    }
313
 
  }
314
 
 
315
 
  return RemoveActionByID(action_id);
316
 
}
317
 
 
318
309
void GnomeGrabber::Impl::ActivateDBusAction(CompAction const& action, uint32_t action_id, uint32_t device, uint32_t timestamp) const
319
310
{
320
311
  LOG_DEBUG(logger) << "ActivateAction (" << action_id << " \"" << action.keyToString() << "\")";