Skip to content

Commit

Permalink
remove event_queue::original_value
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jul 10, 2017
1 parent ca0a49e commit ae9bc80
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 139 deletions.
5 changes: 2 additions & 3 deletions src/core/grabber/include/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,12 @@ class device_grabber final {
merged_input_event_queue_.push_back_event(queued_event);
} else {
// device is ignored
auto event = event_queue::queued_event::event::make_event_from_ignored_device(queued_event.get_event().get_type(),
queued_event.get_event().get_integer_value());
auto event = event_queue::queued_event::event::make_event_from_ignored_device_event();
merged_input_event_queue_.emplace_back_event(queued_event.get_device_id(),
queued_event.get_time_stamp(),
event,
queued_event.get_event_type(),
event);
queued_event.get_event());
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/core/grabber/include/manipulator/details/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ class base {
const event_queue& output_event_queue,
uint64_t time_stamp) = 0;

virtual void handle_event_from_ignored_device(event_queue::queued_event::event::type original_type,
int64_t original_integer_value,
event_type event_type,
event_queue& output_event_queue,
uint64_t time_stamp) = 0;
virtual void handle_event_from_ignored_device(const event_queue::queued_event& front_input_event,
event_queue& output_event_queue) = 0;

bool get_valid(void) const {
return valid_;
Expand Down
68 changes: 32 additions & 36 deletions src/core/grabber/include/manipulator/details/basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,22 @@ class basic final : public base {
virtual void manipulate(event_queue::queued_event& front_input_event,
const event_queue& input_event_queue,
event_queue& output_event_queue) {
bool key_or_button = false;
unset_alone_if_needed(front_input_event.get_event(),
front_input_event.get_event_type());

bool is_target = false;

if (auto key_code = front_input_event.get_event().get_key_code()) {
key_or_button = true;
if (from_.get_key_code() == key_code) {
is_target = true;
}
}
if (auto pointing_button = front_input_event.get_event().get_pointing_button()) {
key_or_button = true;
if (from_.get_pointing_button() == pointing_button) {
is_target = true;
}
}

if (key_or_button) {
if (front_input_event.get_event_type() == event_type::key_down) {
for (auto& e : manipulated_original_events_) {
e.unset_alone();
}
}
}

if (!front_input_event.get_valid()) {
return;
}
Expand Down Expand Up @@ -298,31 +290,10 @@ class basic final : public base {
std::end(manipulated_original_events_));
}

virtual void handle_event_from_ignored_device(event_queue::queued_event::event::type original_type,
int64_t original_integer_value,
event_type event_type,
event_queue& output_event_queue,
uint64_t time_stamp) {
bool need_to_unset_alone = false;

if (original_type == event_queue::queued_event::event::type::key_code ||
original_type == event_queue::queued_event::event::type::pointing_button) {
if (event_type == event_type::key_down) {
need_to_unset_alone = true;
}
}
if (original_type == event_queue::queued_event::event::type::pointing_vertical_wheel ||
original_type == event_queue::queued_event::event::type::pointing_horizontal_wheel) {
if (original_integer_value != 0) {
need_to_unset_alone = true;
}
}

if (need_to_unset_alone) {
for (auto& e : manipulated_original_events_) {
e.unset_alone();
}
}
virtual void handle_event_from_ignored_device(const event_queue::queued_event& front_input_event,
event_queue& output_event_queue) {
unset_alone_if_needed(front_input_event.get_original_event(),
front_input_event.get_event_type());
}

const from_event_definition& get_from(void) const {
Expand Down Expand Up @@ -414,6 +385,31 @@ class basic final : public base {
}
}

void unset_alone_if_needed(const event_queue::queued_event::event& event,
event_type event_type) {
if (event.get_type() == event_queue::queued_event::event::type::key_code ||
event.get_type() == event_queue::queued_event::event::type::pointing_button) {
if (event_type == event_type::key_down) {
goto run;
}
}
if (event.get_type() == event_queue::queued_event::event::type::pointing_vertical_wheel ||
event.get_type() == event_queue::queued_event::event::type::pointing_horizontal_wheel) {
if (auto integer_value = event.get_integer_value()) {
if (*integer_value != 0) {
goto run;
}
}
}

return;

run:
for (auto& e : manipulated_original_events_) {
e.unset_alone();
}
}

core_configuration::profile::complex_modifications::parameters parameters_;

from_event_definition from_;
Expand Down
7 changes: 2 additions & 5 deletions src/core/grabber/include/manipulator/details/nop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ class nop final : public base {
uint64_t time_stamp) {
}

virtual void handle_event_from_ignored_device(event_queue::queued_event::event::type original_type,
int64_t original_integer_value,
event_type event_type,
event_queue& output_event_queue,
uint64_t time_stamp) {
virtual void handle_event_from_ignored_device(const event_queue::queued_event& front_input_event,
event_queue& output_event_queue) {
}
};
} // namespace details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,11 @@ class post_event_to_virtual_devices final : public base {
time_stamp);
}

virtual void handle_event_from_ignored_device(event_queue::queued_event::event::type original_type,
int64_t original_integer_value,
event_type event_type,
event_queue& output_event_queue,
uint64_t time_stamp) {
virtual void handle_event_from_ignored_device(const event_queue::queued_event& front_input_event,
event_queue& output_event_queue) {
key_event_dispatcher_.dispatch_modifier_key_event(output_event_queue.get_modifier_flag_manager(),
queue_,
time_stamp);
front_input_event.get_time_stamp());
}

virtual void set_valid(bool value) {
Expand Down
13 changes: 3 additions & 10 deletions src/core/grabber/include/manipulator/manipulator_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,9 @@ class manipulator_manager final {
break;

case event_queue::queued_event::event::type::event_from_ignored_device:
if (auto original_type = front_input_event.get_event().get_original_type()) {
if (auto original_integer_value = front_input_event.get_event().get_original_integer_value()) {
for (auto&& m : manipulators_) {
m->handle_event_from_ignored_device(*original_type,
*original_integer_value,
front_input_event.get_event_type(),
output_event_queue,
front_input_event.get_time_stamp());
}
}
for (auto&& m : manipulators_) {
m->handle_event_from_ignored_device(front_input_event,
output_event_queue);
}
break;

Expand Down
51 changes: 2 additions & 49 deletions src/share/event_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,8 @@ class event_queue final {
return make_virtual_event(type::device_ungrabbed);
}

static event make_event_from_ignored_device(type original_type,
boost::optional<int64_t> original_integer_value) {
event e;
e.type_ = type::event_from_ignored_device;
e.value_ = original_value(original_type,
(original_integer_value ? *original_integer_value : 0));
return e;
static event make_event_from_ignored_device_event(void) {
return make_virtual_event(type::event_from_ignored_device);
}

static event make_frontmost_application_changed_event(const std::string& bundle_identifier,
Expand Down Expand Up @@ -104,22 +99,6 @@ class event_queue final {
return boost::none;
}

boost::optional<type> get_original_type(void) const {
if (type_ == type::event_from_ignored_device) {
const auto& v = boost::get<original_value>(value_);
return v.get_type();
}
return boost::none;
}

boost::optional<int64_t> get_original_integer_value(void) const {
if (type_ == type::event_from_ignored_device) {
const auto& v = boost::get<original_value>(value_);
return v.get_integer_value();
}
return boost::none;
}

boost::optional<std::string> get_frontmost_application_bundle_identifier(void) const {
if (type_ == type::frontmost_application_changed) {
const auto& v = boost::get<frontmost_application>(value_);
Expand All @@ -142,31 +121,6 @@ class event_queue final {
}

private:
class original_value final {
public:
original_value(type type,
int64_t integer_value) : type_(type),
integer_value_(integer_value) {
}

type get_type(void) const {
return type_;
}

int64_t get_integer_value(void) const {
return integer_value_;
}

bool operator==(const original_value& other) const {
return type_ == other.type_ &&
integer_value_ == other.integer_value_;
}

private:
type type_;
int64_t integer_value_;
};

class frontmost_application final {
public:
frontmost_application(const std::string& bundle_identifier,
Expand Down Expand Up @@ -208,7 +162,6 @@ class event_queue final {
pointing_button, // For type::pointing_button
int64_t, // For type::pointing_x, type::pointing_y, type::pointing_vertical_wheel, type::pointing_horizontal_wheel
boost::blank, // For virtual events
original_value, // For type::event_from_ignored_device
frontmost_application>
value_;
};
Expand Down
15 changes: 0 additions & 15 deletions tests/src/event_queue/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,6 @@ krbn::event_queue::queued_event::event caps_lock_state_changed_0_event(krbn::eve
auto device_keys_are_released_event = krbn::event_queue::queued_event::event::make_device_keys_are_released_event();
} // namespace

TEST_CASE("constructor") {
{
auto event = krbn::event_queue::queued_event::event::make_event_from_ignored_device(krbn::event_queue::queued_event::event::type::key_code, boost::none);
REQUIRE(event.get_type() == krbn::event_queue::queued_event::event::type::event_from_ignored_device);
REQUIRE(event.get_original_type() == krbn::event_queue::queued_event::event::type::key_code);
REQUIRE(event.get_original_integer_value() == static_cast<int64_t>(0));
}
{
auto event = krbn::event_queue::queued_event::event::make_event_from_ignored_device(krbn::event_queue::queued_event::event::type::pointing_y, -100);
REQUIRE(event.get_type() == krbn::event_queue::queued_event::event::type::event_from_ignored_device);
REQUIRE(event.get_original_type() == krbn::event_queue::queued_event::event::type::pointing_y);
REQUIRE(event.get_original_integer_value() == static_cast<int64_t>(-100));
}
}

TEST_CASE("get_key_code") {
REQUIRE(spacebar_event.get_key_code() == krbn::key_code::spacebar);
REQUIRE(button2_event.get_key_code() == boost::none);
Expand Down
26 changes: 16 additions & 10 deletions tests/src/post_event_to_virtual_devices/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
krbn::event_type::EVENT_TYPE, \
EVENT);

#define ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(QUEUE, DEVICE_ID, TIME_STAMP, EVENT, EVENT_TYPE) \
QUEUE.emplace_back_event(krbn::device_id(DEVICE_ID), \
TIME_STAMP, \
krbn::event_queue::queued_event::event::make_event_from_ignored_device_event(), \
krbn::event_type::EVENT_TYPE, \
EVENT);

#define ENQUEUE_LAZY_EVENT(QUEUE, DEVICE_ID, TIME_STAMP, EVENT, EVENT_TYPE) \
QUEUE.emplace_back_event(krbn::device_id(DEVICE_ID), \
TIME_STAMP, \
Expand Down Expand Up @@ -72,12 +79,11 @@ krbn::event_queue::queued_event::event up_arrow_event(krbn::key_code::up_arrow);
krbn::event_queue::queued_event::event button1_event(krbn::pointing_button::button1);
krbn::event_queue::queued_event::event pointing_x_m10_event(krbn::event_queue::queued_event::event::type::pointing_x, -10);
krbn::event_queue::queued_event::event pointing_y_10_event(krbn::event_queue::queued_event::event::type::pointing_y, 10);
krbn::event_queue::queued_event::event pointing_vertical_wheel_0_event(krbn::event_queue::queued_event::event::type::pointing_vertical_wheel, 0);
krbn::event_queue::queued_event::event pointing_vertical_wheel_100_event(krbn::event_queue::queued_event::event::type::pointing_vertical_wheel, 100);
auto device_ungrabbed_event = krbn::event_queue::queued_event::event::make_device_ungrabbed_event();
auto device_keys_are_released_event = krbn::event_queue::queued_event::event::make_device_keys_are_released_event();
auto event_from_ignored_device_key_code_event = krbn::event_queue::queued_event::event::make_event_from_ignored_device(krbn::event_queue::queued_event::event::type::key_code, boost::none);
auto event_from_ignored_device_pointing_x_100_event = krbn::event_queue::queued_event::event::make_event_from_ignored_device(krbn::event_queue::queued_event::event::type::pointing_x, 100);
auto event_from_ignored_device_pointing_vertical_wheel_0_event = krbn::event_queue::queued_event::event::make_event_from_ignored_device(krbn::event_queue::queued_event::event::type::pointing_vertical_wheel, 0);
auto event_from_ignored_device_pointing_vertical_wheel_100_event = krbn::event_queue::queued_event::event::make_event_from_ignored_device(krbn::event_queue::queued_event::event::type::pointing_vertical_wheel, 100);
auto event_from_ignored_device_event = krbn::event_queue::queued_event::event::make_event_from_ignored_device_event();

uint64_t modifier_wait = krbn::time_utility::nano_to_absolute(NSEC_PER_MSEC);
} // namespace
Expand Down Expand Up @@ -1110,17 +1116,17 @@ TEST_CASE("actual examples") {
time_stamp = 0;

ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, right_control_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, event_from_ignored_device_key_code_event, key_down);
ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(helper.get_input_event_queue(), 2, time_stamp += interval, spacebar_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, right_control_event, key_up);

ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, right_control_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, event_from_ignored_device_pointing_vertical_wheel_100_event, key_down);
ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(helper.get_input_event_queue(), 2, time_stamp += interval, pointing_vertical_wheel_100_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, right_control_event, key_up);

ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, right_control_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, event_from_ignored_device_key_code_event, key_up);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, event_from_ignored_device_pointing_x_100_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, event_from_ignored_device_pointing_vertical_wheel_0_event, key_down);
ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(helper.get_input_event_queue(), 2, time_stamp += interval, spacebar_event, key_up);
ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, pointing_x_m10_event, key_down);
ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, pointing_vertical_wheel_0_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, right_control_event, key_up);

helper.manipulate();
Expand Down Expand Up @@ -1298,7 +1304,7 @@ TEST_CASE("actual examples") {
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, left_control_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, p_event, key_down);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, p_event, key_up);
ENQUEUE_EVENT(helper.get_input_event_queue(), 1, time_stamp += interval, event_from_ignored_device_key_code_event, key_up);
ENQUEUE_EVENT_FROM_IGNORED_DEVICE_EVENT(helper.get_input_event_queue(), 2, time_stamp += interval, spacebar_event, key_up);

helper.manipulate();

Expand Down

0 comments on commit ae9bc80

Please sign in to comment.