Skip to content

Commit

Permalink
add frontmost_application_changed to event_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jul 6, 2017
1 parent 71e0aa9 commit 753c548
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
7 changes: 7 additions & 0 deletions appendix/dump_hid_value/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <IOKit/hidsystem/IOHIDShared.h>
#include <IOKit/hidsystem/ev_keymap.h>
#include <boost/bind.hpp>
#include <boost/optional/optional_io.hpp>
#include <iostream>
#include <mach/mach_time.h>

Expand Down Expand Up @@ -166,6 +167,12 @@ class dump_hid_value final {
case krbn::event_queue::queued_event::event::type::event_from_ignored_device:
std::cout << "event_from_ignored_device from " << device.get_name_for_log() << " (" << device.get_device_id() << ")" << std::endl;
break;

case krbn::event_queue::queued_event::event::type::frontmost_application_changed:
std::cout << "frontmost_application_changed "
<< queued_event.get_event().get_frontmost_application_bundle_identifier() << " "
<< queued_event.get_event().get_frontmost_application_file_path() << std::endl;
break;
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/core/grabber/include/device_grabber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ class device_grabber final {
update_fn_function_keys_manipulators();
}

void post_frontmost_application_changed_event(const std::string& bundle_identifier,
const std::string& file_path) {
auto event = event_queue::queued_event::event::make_frontmost_application_changed(bundle_identifier,
file_path);
merged_input_event_queue_.emplace_back_event(device_id(0),
mach_absolute_time(),
event,
event_type::key_down,
event);
manipulate();
}

private:
enum class mode {
observing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class post_event_to_virtual_devices final : public base {
case event_queue::queued_event::event::type::device_ungrabbed:
case event_queue::queued_event::event::type::caps_lock_state_changed:
case event_queue::queued_event::event::type::event_from_ignored_device:
case event_queue::queued_event::event::type::frontmost_application_changed:
// Do nothing
break;
}
Expand All @@ -431,6 +432,7 @@ class post_event_to_virtual_devices final : public base {
case event_queue::queued_event::event::type::device_ungrabbed:
case event_queue::queued_event::event::type::caps_lock_state_changed:
case event_queue::queued_event::event::type::event_from_ignored_device:
case event_queue::queued_event::event::type::frontmost_application_changed:
// Do nothing
break;
}
Expand Down
12 changes: 11 additions & 1 deletion src/core/grabber/include/manipulator/manipulator_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ class manipulator_manager final {
}
break;

default:
case event_queue::queued_event::event::type::caps_lock_state_changed:
case event_queue::queued_event::event::type::frontmost_application_changed:
// Do nothing
break;

case event_queue::queued_event::event::type::key_code:
case event_queue::queued_event::event::type::pointing_button:
case event_queue::queued_event::event::type::pointing_x:
case event_queue::queued_event::event::type::pointing_y:
case event_queue::queued_event::event::type::pointing_vertical_wheel:
case event_queue::queued_event::event::type::pointing_horizontal_wheel:
for (auto&& m : manipulators_) {
m->manipulate(front_input_event,
input_event_queue,
Expand Down
7 changes: 5 additions & 2 deletions src/core/grabber/include/receiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ class receiver final {
if (n < sizeof(operation_type_frontmost_application_changed_struct)) {
logger::get_logger().error("invalid size for operation_type::frontmost_application_changed ({0})", n);
} else {
//auto p = reinterpret_cast<operation_type_frontmost_application_changed_struct*>(&(buffer_[0]));
//logger::get_logger().info("frontmost_application_changed");
auto p = reinterpret_cast<operation_type_frontmost_application_changed_struct*>(&(buffer_[0]));
device_grabber_.post_frontmost_application_changed_event(p->bundle_identifier,
p->file_path);
}
break;

Expand All @@ -106,6 +107,8 @@ class receiver final {
}

void console_user_server_exit_callback(void) {
device_grabber_.post_frontmost_application_changed_event("", "");

device_grabber_.stop_grabbing();

start_grabbing_if_system_core_configuration_file_exists();
Expand Down
34 changes: 34 additions & 0 deletions src/share/event_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class event_queue final {
device_ungrabbed,
caps_lock_state_changed,
event_from_ignored_device,
frontmost_application_changed,
};

event(key_code key_code) : type_(type::key_code),
Expand All @@ -54,6 +55,14 @@ class event_queue final {
return e;
}

static event make_frontmost_application_changed(const std::string& bundle_identifier,
const std::string& file_path) {
event e;
e.type_ = type::frontmost_application_changed;
e.value_ = frontmost_application(bundle_identifier, file_path);
return e;
}

type get_type(void) const {
return type_;
}
Expand Down Expand Up @@ -99,6 +108,22 @@ class event_queue final {
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_);
return v.get_bundle_identifier();
}
return boost::none;
}

boost::optional<std::string> get_frontmost_application_file_path(void) const {
if (type_ == type::frontmost_application_changed) {
const auto& v = boost::get<frontmost_application>(value_);
return v.get_file_path();
}
return boost::none;
}

bool operator==(const event& other) const {
return get_type() == other.get_type() &&
value_ == other.value_;
Expand Down Expand Up @@ -389,6 +414,14 @@ class event_queue final {
}
}
}

// Update manipulator_environment
if (auto bundle_identifier = event.get_frontmost_application_bundle_identifier()) {
if (auto file_path = event.get_frontmost_application_file_path()) {
manipulator_environment_.get_frontmost_application().set_bundle_identifier(*bundle_identifier);
manipulator_environment_.get_frontmost_application().set_file_path(*file_path);
}
}
}

void push_back_event(const queued_event& queued_event) {
Expand Down Expand Up @@ -550,6 +583,7 @@ class event_queue final {
std::vector<queued_event> events_;
modifier_flag_manager modifier_flag_manager_;
pointing_button_manager pointing_button_manager_;
manipulator_environment manipulator_environment_;
uint64_t time_stamp_delay_;
}; // namespace krbn

Expand Down
14 changes: 14 additions & 0 deletions src/share/manipulator_environment.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include "logger.hpp"

namespace krbn {
class manipulator_environment final {
Expand All @@ -11,13 +12,15 @@ class manipulator_environment final {
return bundle_identifier_;
}
void set_bundle_identifier(const std::string& value) {
//logger::get_logger().info("bundle_identifier_ {0}", value);
bundle_identifier_ = value;
}

const std::string& get_file_path(void) const {
return file_path_;
}
void set_file_path(const std::string& value) {
//logger::get_logger().info("file_path_ {0}", value);
file_path_ = value;
}

Expand All @@ -28,6 +31,17 @@ class manipulator_environment final {

manipulator_environment(const manipulator_environment&) = delete;

manipulator_environment(void) {
}

frontmost_application& get_frontmost_application(void) {
return frontmost_application_;
}

const frontmost_application& get_frontmost_application(void) const {
return frontmost_application_;
}

private:
frontmost_application frontmost_application_;
};
Expand Down

0 comments on commit 753c548

Please sign in to comment.